This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Support mapping complex types #43
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from odd_collector_aws.logger import logger | ||
|
||
|
||
def get_version() -> str: | ||
try: | ||
from odd_collector_aws.__version__ import VERSION | ||
|
||
return VERSION | ||
except Exception as e: | ||
logger.warning(f"Can't get version from odd_collector_gcp.__version__. {e}") | ||
return "-" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
from pathlib import Path | ||
|
||
import odd_collector_sdk as sdk | ||
from odd_collector_sdk.collector import Collector | ||
|
||
from odd_collector_aws import get_version | ||
from odd_collector_aws.domain.plugin import PLUGIN_FACTORY | ||
from odd_collector_aws.logger import logger | ||
|
||
COLLECTOR_PACKAGE = __package__ | ||
CONFIG_PATH = Path().cwd() / "collector_config.yaml" | ||
|
||
logger.info(f"GCP collector version: {get_version()}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aws |
||
logger.info(f"SDK: {sdk.get_version()}") | ||
|
||
collector = Collector( | ||
config_path=CONFIG_PATH, | ||
root_package=COLLECTOR_PACKAGE, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VERSION = "0.1.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,38 @@ | ||
from deltalake._internal import ArrayType, Field, MapType, PrimitiveType, StructType | ||
from odd_models.models import DataSetField, DataSetFieldType, Type | ||
from pathlib import Path | ||
from odd_collector_sdk.grammar_parser.build_dataset_field import DatasetFieldBuilder | ||
from odd_models.models import DataSetField, Type | ||
from oddrn_generator import S3Generator | ||
|
||
from ..logger import logger | ||
|
||
DELTA_TO_ODD_TYPE_MAP = { | ||
from ..models.field import DField | ||
|
||
DELTA_TO_ODD_TYPE_MAP: dict[str, Type] = { | ||
"float": Type.TYPE_NUMBER, | ||
"struct": Type.TYPE_STRUCT, | ||
"bigint": Type.TYPE_INTEGER, | ||
"binary": Type.TYPE_BINARY, | ||
"boolean": Type.TYPE_BOOLEAN, | ||
"date": Type.TYPE_DATETIME, | ||
"decimal": Type.TYPE_NUMBER, | ||
"double": Type.TYPE_NUMBER, | ||
"void": Type.TYPE_UNKNOWN, | ||
"smallint": Type.TYPE_INTEGER, | ||
"timestamp": Type.TYPE_TIME, | ||
"tinyint": Type.TYPE_INTEGER, | ||
"array": Type.TYPE_LIST, | ||
"map": Type.TYPE_MAP, | ||
"int": Type.TYPE_INTEGER, | ||
"long": Type.TYPE_INTEGER, | ||
"string": Type.TYPE_STRING, | ||
"interval": Type.TYPE_DURATION, | ||
} | ||
|
||
|
||
def map_to_odd_type(delta_type: str) -> Type: | ||
return DELTA_TO_ODD_TYPE_MAP.get(delta_type, Type.TYPE_UNKNOWN) | ||
|
||
|
||
def unknown_field(generator: S3Generator, field: Field) -> DataSetField: | ||
generator.set_oddrn_paths(columns=field.name) | ||
return DataSetField( | ||
oddrn=generator.get_oddrn_by_path("columns"), | ||
name=field.name, | ||
type=DataSetFieldType( | ||
type=Type.TYPE_UNKNOWN, | ||
logical_type=field.type, | ||
is_nullable=field.nullable, | ||
), | ||
def map_field(oddrn_generator: S3Generator, column: DField) -> list[DataSetField]: | ||
field_builder = DatasetFieldBuilder( | ||
data_source="s3_delta", | ||
oddrn_generator=oddrn_generator, | ||
parser_config_path=Path( | ||
"odd_collector_aws/adapters/s3_delta/mappers/grammar/field_types.lark" | ||
).absolute(), | ||
odd_types_map=DELTA_TO_ODD_TYPE_MAP, | ||
) | ||
|
||
|
||
def map_primitive(generator: S3Generator, field: Field) -> DataSetField: | ||
generator.set_oddrn_paths(columns=field.name) | ||
return DataSetField( | ||
oddrn=generator.get_oddrn_by_path("columns"), | ||
name=field.name, | ||
type=DataSetFieldType( | ||
type=map_to_odd_type(field.type.type), | ||
logical_type=field.type.type, | ||
is_nullable=field.nullable, | ||
), | ||
) | ||
|
||
|
||
def map_map(generator: S3Generator, field: Field) -> DataSetField: | ||
... | ||
|
||
|
||
def map_struct(generator: S3Generator, field: Field) -> DataSetField: | ||
... | ||
|
||
|
||
def map_array(generator: S3Generator, field: Field) -> DataSetField: | ||
... | ||
|
||
|
||
def map_field(generator: S3Generator, field: Field) -> DataSetField: | ||
type_ = field.type | ||
|
||
if isinstance(type_, PrimitiveType): | ||
return map_primitive(generator, field) | ||
else: | ||
logger.error(f"Unknown field type: {field.type}") | ||
return field_builder.build_dataset_field(column) |
40 changes: 40 additions & 0 deletions
40
odd_collector_aws/adapters/s3_delta/mappers/grammar/field_types.lark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
?start: type | ||
|
||
BASIC_TYPE: "string" | ||
| "int" | ||
| "float" | ||
| "double" | ||
| "bigint" | ||
| "binary" | ||
| "boolean" | ||
| "date" | ||
| "decimal" | ||
| "void" | ||
| "interval" | ||
| "smallint" | ||
| "timestamp" | ||
| "timestamp_ntz" | ||
| "tinyint" | ||
| "long" | ||
|
||
primitive_type: "PrimitiveType(\"" BASIC_TYPE "\")" | ||
|
||
FIELD_NAME: (LETTER | "_") (LETTER | "_" | DIGIT | "-")* | ||
|
||
array: "ArrayType" "(" type ", " "contains_null=" BOOL ")" | ||
|
||
field: "Field(" FIELD_NAME ", " type ", " "nullable=" BOOL ")" | ||
|
||
struct: "StructType([" [field (", " field)*] "])" | ||
|
||
map: "MapType(" type ", " type ", " "value_contains_null=" BOOL ")" | ||
|
||
?type: primitive_type | ||
| array | ||
| struct | ||
| map | ||
|
||
BOOL: "True" | "False" | ||
|
||
%import common.LETTER | ||
%import common.DIGIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import Union | ||
|
||
from deltalake import Field | ||
from deltalake._internal import PrimitiveType, ArrayType, MapType, StructType | ||
|
||
|
||
class DField: | ||
def __init__(self, field: Field): | ||
self.field = field | ||
|
||
@property | ||
def odd_metadata(self) -> dict: | ||
return self.field.metadata | ||
|
||
@property | ||
def name(self) -> str: | ||
return self.field.name | ||
|
||
@property | ||
def type(self) -> Union[PrimitiveType, ArrayType, MapType, StructType]: | ||
return self.field.type | ||
|
||
@property | ||
def nullable(self) -> bool: | ||
return self.nullable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aws