You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/08/07 16:16:12 UTC
[GitHub] [iceberg] rdblue commented on a diff in pull request #5447: Python: Implement Hive create and load table
rdblue commented on code in PR #5447:
URL: https://github.com/apache/iceberg/pull/5447#discussion_r939690764
##########
python/pyiceberg/catalog/hive.py:
##########
@@ -159,16 +156,56 @@ def _construct_parameters(metadata_location: str, previous_metadata_location: Op
def _annotate_namespace(database: HiveDatabase, properties: Properties) -> HiveDatabase:
params = {}
for key, value in properties.items():
- if key == "comment":
+ if key == COMMENT:
database.description = value
- elif key == "location":
+ elif key == LOCATION:
database.locationUri = value
else:
params[key] = value
database.parameters = params
return database
+hive_primitive_types = {
+ BooleanType: "boolean",
+ IntegerType: "int",
+ LongType: "bigint",
+ FloatType: "float",
+ DoubleType: "double",
+ DateType: "date",
+ TimeType: "string",
+ TimestampType: "timestamp",
+ StringType: "string",
+ UUIDType: "string",
+ BinaryType: "binary",
+ FixedType: "binary",
+}
+
+
+class HiveSchemaConstructor(SchemaVisitor[str]):
+ def schema(self, schema: Schema, struct_result: str) -> str:
+ return struct_result
+
+ def struct(self, struct: StructType, field_results: List[str]) -> str:
+ return f"struct<{', '.join(field_results)}>"
+
+ def field(self, field: NestedField, field_result: str) -> str:
+ return f"{field.name}: {field_result}"
+
+ def list(self, list_type: ListType, element_result: str) -> str:
+ return f"array<{element_result}>"
+
+ def map(self, map_type: MapType, key_result: str, value_result: str) -> str:
+ # Key has to be primitive for Hive
+ return f"map<{key_result}, {value_result}>"
+
+ def primitive(self, primitive: PrimitiveType) -> str:
+ if isinstance(primitive, DecimalType):
+ return f"DECIMAL({primitive.precision}, {primitive.scale})"
Review Comment:
Why is decimal upper case but the others aren't?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org