voonhous commented on code in PR #17659:
URL: https://github.com/apache/hudi/pull/17659#discussion_r2672345953
##########
hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java:
##########
@@ -107,185 +104,117 @@ public TableSchemaResolver(HoodieTableMetaClient
metaClient) {
this.hasOperationField = Lazy.lazily(this::hasOperationField);
}
- public Schema getTableAvroSchemaFromDataFile() throws Exception {
- return
getTableAvroSchemaFromDataFileInternal().orElseThrow(schemaNotFoundError());
- }
-
/**
* Gets full schema (user + metadata) for a hoodie table from data file as
HoodieSchema.
- * Delegates to getTableAvroSchemaFromDataFile and wraps the result in a
HoodieSchema.
*
* @return HoodieSchema for this table from data file
* @throws Exception
*/
public HoodieSchema getTableSchemaFromDataFile() throws Exception {
- Schema avroSchema = getTableAvroSchemaFromDataFile();
- return HoodieSchema.fromAvroSchema(avroSchema);
+ return
getTableSchemaFromDataFileInternal().orElseThrow(schemaNotFoundError());
}
- private Option<Schema> getTableAvroSchemaFromDataFileInternal() {
+ private Option<HoodieSchema> getTableSchemaFromDataFileInternal() {
return getTableParquetSchemaFromDataFile();
}
/**
- * Gets full schema (user + metadata) for a hoodie table as HoodieSchema.
- * Delegates to getTableAvroSchema and wraps the result in a HoodieSchema.
+ * Gets full schema (user + metadata) for a hoodie table.
*
- * @return HoodieSchema for this table
+ * @return Avro schema for this table
* @throws Exception
*/
public HoodieSchema getTableSchema() throws Exception {
- Schema avroSchema =
getTableAvroSchema(metaClient.getTableConfig().populateMetaFields());
- return HoodieSchema.fromAvroSchema(avroSchema);
+ return getTableSchema(metaClient.getTableConfig().populateMetaFields());
}
/**
- * Gets full schema (user + metadata) for a hoodie table as HoodieSchema.
- * Delegates to getTableAvroSchema and wraps the result in a HoodieSchema.
+ * Gets schema for a hoodie table, can choose if include metadata fields
should be included.
*
* @param includeMetadataFields choice if include metadata fields
- * @return HoodieSchema for this table
+ * @return Hoodie schema for this table
* @throws Exception
*/
public HoodieSchema getTableSchema(boolean includeMetadataFields) throws
Exception {
- Schema avroSchema = getTableAvroSchema(includeMetadataFields);
- return HoodieSchema.fromAvroSchema(avroSchema);
+ return getTableSchemaInternal(includeMetadataFields,
Option.empty()).orElseThrow(schemaNotFoundError());
}
/**
- * Fetches tables schema in Avro format as of the given instant as
HoodieSchema.
+ * Fetches tables schema as of the given instant
*
* @param timestamp as of which table's schema will be fetched
*/
public HoodieSchema getTableSchema(String timestamp) throws Exception {
- Schema avroSchema = getTableAvroSchema(timestamp);
- return HoodieSchema.fromAvroSchema(avroSchema);
- }
-
- /**
- * Fetches HoodieSchema as of the given instant
- *
- * @param instant as of which table's schema will be fetched
- */
- public HoodieSchema getTableSchema(HoodieInstant instant, boolean
includeMetadataFields) throws Exception {
- Schema schema = getTableAvroSchema(instant, includeMetadataFields);
- return HoodieSchema.fromAvroSchema(schema);
- }
-
- public Option<HoodieSchema> getTableSchemaIfPresent(boolean
includeMetadataFields) {
- return getTableAvroSchemaInternal(includeMetadataFields,
Option.empty()).map(HoodieSchema::fromAvroSchema);
- }
-
- /**
- * Gets full schema (user + metadata) for a hoodie table in Avro format.
- *
- * @return Avro schema for this table
- * @throws Exception
- */
- public Schema getTableAvroSchema() throws Exception {
- return
getTableAvroSchema(metaClient.getTableConfig().populateMetaFields());
- }
-
- /**
- * Gets schema for a hoodie table in Avro format, can choice if include
metadata fields.
- *
- * @param includeMetadataFields choice if include metadata fields
- * @return Avro schema for this table
- * @throws Exception
- */
- public Schema getTableAvroSchema(boolean includeMetadataFields) throws
Exception {
- return getTableAvroSchemaInternal(includeMetadataFields,
Option.empty()).orElseThrow(schemaNotFoundError());
- }
-
- /**
- * Fetches tables schema in Avro format as of the given instant
- *
- * @param timestamp as of which table's schema will be fetched
- */
- public Schema getTableAvroSchema(String timestamp) throws Exception {
Option<HoodieInstant> instant =
metaClient.getActiveTimeline().getCommitsTimeline()
.filterCompletedInstants()
.findInstantsBeforeOrEquals(timestamp)
.lastInstant();
- return
getTableAvroSchemaInternal(metaClient.getTableConfig().populateMetaFields(),
instant)
+ return
getTableSchemaInternal(metaClient.getTableConfig().populateMetaFields(),
instant)
.orElseThrow(schemaNotFoundError());
}
/**
- * Fetches tables schema in Avro format as of the given instant
+ * Fetches tables schema as of the given instant
*
* @param instant as of which table's schema will be fetched
*/
- public Schema getTableAvroSchema(HoodieInstant instant, boolean
includeMetadataFields) throws Exception {
- return getTableAvroSchemaInternal(includeMetadataFields,
Option.of(instant)).orElseThrow(schemaNotFoundError());
- }
-
- /**
- * Gets users data schema for a hoodie table in Avro format.
- *
- * @return Avro user data schema
- * @throws Exception
- *
- * @deprecated use {@link #getTableAvroSchema(boolean)} instead
- */
- @Deprecated
- public Schema getTableAvroSchemaWithoutMetadataFields() throws Exception {
- return getTableAvroSchemaInternal(false,
Option.empty()).orElseThrow(schemaNotFoundError());
+ public HoodieSchema getTableSchema(HoodieInstant instant, boolean
includeMetadataFields) throws Exception {
+ return getTableSchemaInternal(includeMetadataFields,
Option.of(instant)).orElseThrow(schemaNotFoundError());
}
- public Option<Schema> getTableAvroSchemaIfPresent(boolean
includeMetadataFields) {
- return getTableAvroSchemaInternal(includeMetadataFields, Option.empty());
+ public Option<HoodieSchema> getTableSchemaIfPresent(boolean
includeMetadataFields) {
+ return getTableSchemaInternal(includeMetadataFields, Option.empty());
}
- private Option<Schema> getTableAvroSchemaInternal(boolean
includeMetadataFields, Option<HoodieInstant> instantOpt) {
- Option<Schema> schema =
+ private Option<HoodieSchema> getTableSchemaInternal(boolean
includeMetadataFields, Option<HoodieInstant> instantOpt) {
+ Option<HoodieSchema> schema =
(instantOpt.isPresent()
? getTableSchemaFromCommitMetadata(instantOpt.get(),
includeMetadataFields)
: getTableSchemaFromLatestCommitMetadata(includeMetadataFields))
.or(() ->
metaClient.getTableConfig().getTableCreateSchema()
Review Comment:
Shouldn't be too big, doing it now.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]