HoodieTableMetaClient initializeHudiTable()

in xtable-core/src/main/java/org/apache/xtable/hudi/HudiTableManager.java [87:124]


  HoodieTableMetaClient initializeHudiTable(String tableDataPath, InternalTable table) {
    String recordKeyField = "";
    if (table.getReadSchema() != null) {
      List<String> recordKeys =
          table.getReadSchema().getRecordKeyFields().stream()
              .map(InternalField::getName)
              .collect(Collectors.toList());
      if (!recordKeys.isEmpty()) {
        recordKeyField = String.join(",", recordKeys);
      }
    }
    String keyGeneratorClass;
    keyGeneratorClass =
        getKeyGeneratorClass(
            table.getPartitioningFields(), table.getReadSchema().getRecordKeyFields());
    boolean hiveStylePartitioningEnabled =
        DataLayoutStrategy.HIVE_STYLE_PARTITION == table.getLayoutStrategy();
    try {
      return HoodieTableMetaClient.withPropertyBuilder()
          .setCommitTimezone(HoodieTimelineTimeZone.UTC)
          .setHiveStylePartitioningEnable(hiveStylePartitioningEnabled)
          .setTableType(HoodieTableType.COPY_ON_WRITE)
          .setTableName(table.getName())
          .setPayloadClass(HoodieAvroPayload.class)
          .setRecordKeyFields(recordKeyField)
          .setKeyGeneratorClassProp(keyGeneratorClass)
          // other formats will not populate meta fields, so we disable it for consistency
          .setPopulateMetaFields(false)
          .setPartitionFields(
              table.getPartitioningFields().stream()
                  .map(InternalPartitionField::getSourceField)
                  .map(InternalField::getPath)
                  .collect(Collectors.joining(",")))
          .initTable(configuration, tableDataPath);
    } catch (IOException ex) {
      throw new UpdateException("Unable to initialize Hudi table", ex);
    }
  }