Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More representative action enum names #33

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions xdlake/delta_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ class WriteMode(Enum):
ignore = "Ignore"

class Actions(Enum):
commitInfo = "commitInfo"
metaData = "metaData"
table_commit = "commitInfo"
table_metadata = "metaData"
protocol = "protocol"
add = "add"
remove = "remove"

@classmethod
def _missing_(cls, v):
for member in cls:
if member.name == v or member.value == v:
return member

class _JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, (datetime.date, datetime.datetime)):
Expand Down Expand Up @@ -177,7 +183,7 @@ class TableMetadata(_DeltaLogAction):
configuration: dict = field(default_factory=lambda: dict())

def to_action_dict(self) -> dict:
return {Actions.metaData.name: self.asdict()}
return {Actions.table_metadata.value: self.asdict()}

@property
def schema(self) -> Schema:
Expand Down Expand Up @@ -219,7 +225,7 @@ class TableCommit(_DeltaLogAction):
def to_action_dict(self) -> dict:
info = {k: v for k, v in self.asdict().items()
if v}
return {Actions.commitInfo.name: info}
return {Actions.table_commit.value: info}

@property
def metadata(self):
Expand Down Expand Up @@ -393,16 +399,16 @@ def load_action(obj: str | bytes | dict) -> _DeltaLogAction:
info = json.loads(obj)
else:
info = obj
action = Actions[set(info.keys()).pop()]
info = info[action.name]
action = Actions(set(info.keys()).pop())
info = info[action.value]

match action:
case Actions.commitInfo:
case Actions.table_commit:
if info["operation"] in TableCommitOperation.values:
return TableCommit.with_info(info)
else:
raise ValueError(f"Unknown operation '{info['operation']}'")
case Actions.metaData:
case Actions.table_metadata:
return TableMetadata.with_info(info)
case Actions.protocol:
return Protocol.with_info(info)
Expand Down
Loading