|
123 | 123 | import static com.facebook.presto.hive.MetadataUtils.getDiscretePredicates;
|
124 | 124 | import static com.facebook.presto.hive.MetadataUtils.getPredicate;
|
125 | 125 | import static com.facebook.presto.hive.MetadataUtils.getSubfieldPredicate;
|
| 126 | +import static com.facebook.presto.hive.metastore.MetastoreUtil.TABLE_COMMENT; |
126 | 127 | import static com.facebook.presto.iceberg.ExpressionConverter.toIcebergExpression;
|
127 | 128 | import static com.facebook.presto.iceberg.IcebergColumnHandle.DATA_SEQUENCE_NUMBER_COLUMN_HANDLE;
|
128 | 129 | import static com.facebook.presto.iceberg.IcebergColumnHandle.DATA_SEQUENCE_NUMBER_COLUMN_METADATA;
|
|
146 | 147 | import static com.facebook.presto.iceberg.IcebergTableProperties.METRICS_MAX_INFERRED_COLUMN;
|
147 | 148 | import static com.facebook.presto.iceberg.IcebergTableProperties.PARTITIONING_PROPERTY;
|
148 | 149 | import static com.facebook.presto.iceberg.IcebergTableProperties.SORTED_BY_PROPERTY;
|
| 150 | +import static com.facebook.presto.iceberg.IcebergTableProperties.getCommitRetries; |
| 151 | +import static com.facebook.presto.iceberg.IcebergTableProperties.getFormatVersion; |
| 152 | +import static com.facebook.presto.iceberg.IcebergTableProperties.getWriteDataLocation; |
149 | 153 | import static com.facebook.presto.iceberg.IcebergTableType.CHANGELOG;
|
150 | 154 | import static com.facebook.presto.iceberg.IcebergTableType.DATA;
|
151 | 155 | import static com.facebook.presto.iceberg.IcebergTableType.EQUALITY_DELETES;
|
|
166 | 170 | import static com.facebook.presto.iceberg.IcebergUtil.getUpdateMode;
|
167 | 171 | import static com.facebook.presto.iceberg.IcebergUtil.getViewComment;
|
168 | 172 | import static com.facebook.presto.iceberg.IcebergUtil.isMetadataDeleteAfterCommit;
|
| 173 | +import static com.facebook.presto.iceberg.IcebergUtil.parseFormatVersion; |
169 | 174 | import static com.facebook.presto.iceberg.IcebergUtil.resolveSnapshotIdByName;
|
170 | 175 | import static com.facebook.presto.iceberg.IcebergUtil.toHiveColumns;
|
171 | 176 | import static com.facebook.presto.iceberg.IcebergUtil.tryGetLocation;
|
|
206 | 211 | import static org.apache.iceberg.SnapshotSummary.DELETED_RECORDS_PROP;
|
207 | 212 | import static org.apache.iceberg.SnapshotSummary.REMOVED_EQ_DELETES_PROP;
|
208 | 213 | import static org.apache.iceberg.SnapshotSummary.REMOVED_POS_DELETES_PROP;
|
| 214 | +import static org.apache.iceberg.TableProperties.COMMIT_NUM_RETRIES; |
| 215 | +import static org.apache.iceberg.TableProperties.DEFAULT_FILE_FORMAT; |
209 | 216 | import static org.apache.iceberg.TableProperties.DELETE_ISOLATION_LEVEL;
|
210 | 217 | import static org.apache.iceberg.TableProperties.DELETE_ISOLATION_LEVEL_DEFAULT;
|
| 218 | +import static org.apache.iceberg.TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED; |
| 219 | +import static org.apache.iceberg.TableProperties.METRICS_MAX_INFERRED_COLUMN_DEFAULTS; |
| 220 | +import static org.apache.iceberg.TableProperties.ORC_COMPRESSION; |
| 221 | +import static org.apache.iceberg.TableProperties.PARQUET_COMPRESSION; |
211 | 222 | import static org.apache.iceberg.TableProperties.SPLIT_SIZE;
|
212 | 223 | import static org.apache.iceberg.TableProperties.UPDATE_MODE;
|
213 | 224 | import static org.apache.iceberg.TableProperties.WRITE_DATA_LOCATION;
|
@@ -1152,6 +1163,62 @@ public void setTableProperties(ConnectorSession session, ConnectorTableHandle ta
|
1152 | 1163 | transaction.commitTransaction();
|
1153 | 1164 | }
|
1154 | 1165 |
|
| 1166 | + protected Map<String, String> populateTableProperties(ConnectorTableMetadata tableMetadata, com.facebook.presto.iceberg.FileFormat fileFormat, ConnectorSession session) |
| 1167 | + { |
| 1168 | + ImmutableMap.Builder<String, String> propertiesBuilder = ImmutableMap.builderWithExpectedSize(16); |
| 1169 | + |
| 1170 | + String writeDataLocation = getWriteDataLocation(tableMetadata.getProperties()); |
| 1171 | + if (!isNullOrEmpty(writeDataLocation)) { |
| 1172 | + propertiesBuilder.put(WRITE_DATA_LOCATION, writeDataLocation); |
| 1173 | + } |
| 1174 | + else { |
| 1175 | + Optional<String> dataLocation = getDataLocationBasedOnWarehouseDataDir(tableMetadata.getTable()); |
| 1176 | + dataLocation.ifPresent(location -> propertiesBuilder.put(WRITE_DATA_LOCATION, location)); |
| 1177 | + } |
| 1178 | + |
| 1179 | + Integer commitRetries = getCommitRetries(tableMetadata.getProperties()); |
| 1180 | + propertiesBuilder.put(DEFAULT_FILE_FORMAT, fileFormat.toString()); |
| 1181 | + propertiesBuilder.put(COMMIT_NUM_RETRIES, String.valueOf(commitRetries)); |
| 1182 | + switch (fileFormat) { |
| 1183 | + case PARQUET: |
| 1184 | + propertiesBuilder.put(PARQUET_COMPRESSION, getCompressionCodec(session).getParquetCompressionCodec().get().toString()); |
| 1185 | + break; |
| 1186 | + case ORC: |
| 1187 | + propertiesBuilder.put(ORC_COMPRESSION, getCompressionCodec(session).getOrcCompressionKind().name()); |
| 1188 | + break; |
| 1189 | + } |
| 1190 | + if (tableMetadata.getComment().isPresent()) { |
| 1191 | + propertiesBuilder.put(TABLE_COMMENT, tableMetadata.getComment().get()); |
| 1192 | + } |
| 1193 | + |
| 1194 | + String formatVersion = getFormatVersion(tableMetadata.getProperties()); |
| 1195 | + verify(formatVersion != null, "Format version cannot be null"); |
| 1196 | + propertiesBuilder.put(TableProperties.FORMAT_VERSION, formatVersion); |
| 1197 | + |
| 1198 | + if (parseFormatVersion(formatVersion) < MIN_FORMAT_VERSION_FOR_DELETE) { |
| 1199 | + propertiesBuilder.put(TableProperties.DELETE_MODE, RowLevelOperationMode.COPY_ON_WRITE.modeName()); |
| 1200 | + propertiesBuilder.put(TableProperties.UPDATE_MODE, RowLevelOperationMode.COPY_ON_WRITE.modeName()); |
| 1201 | + } |
| 1202 | + else { |
| 1203 | + RowLevelOperationMode deleteMode = IcebergTableProperties.getDeleteMode(tableMetadata.getProperties()); |
| 1204 | + propertiesBuilder.put(TableProperties.DELETE_MODE, deleteMode.modeName()); |
| 1205 | + RowLevelOperationMode updateMode = IcebergTableProperties.getUpdateMode(tableMetadata.getProperties()); |
| 1206 | + propertiesBuilder.put(TableProperties.UPDATE_MODE, updateMode.modeName()); |
| 1207 | + } |
| 1208 | + |
| 1209 | + Integer metadataPreviousVersionsMax = IcebergTableProperties.getMetadataPreviousVersionsMax(tableMetadata.getProperties()); |
| 1210 | + propertiesBuilder.put(TableProperties.METADATA_PREVIOUS_VERSIONS_MAX, String.valueOf(metadataPreviousVersionsMax)); |
| 1211 | + |
| 1212 | + Boolean metadataDeleteAfterCommit = IcebergTableProperties.isMetadataDeleteAfterCommit(tableMetadata.getProperties()); |
| 1213 | + propertiesBuilder.put(METADATA_DELETE_AFTER_COMMIT_ENABLED, String.valueOf(metadataDeleteAfterCommit)); |
| 1214 | + |
| 1215 | + Integer metricsMaxInferredColumn = IcebergTableProperties.getMetricsMaxInferredColumn(tableMetadata.getProperties()); |
| 1216 | + propertiesBuilder.put(METRICS_MAX_INFERRED_COLUMN_DEFAULTS, String.valueOf(metricsMaxInferredColumn)); |
| 1217 | + |
| 1218 | + propertiesBuilder.put(SPLIT_SIZE, String.valueOf(IcebergTableProperties.getTargetSplitSize(tableMetadata.getProperties()))); |
| 1219 | + return propertiesBuilder.build(); |
| 1220 | + } |
| 1221 | + |
1155 | 1222 | /**
|
1156 | 1223 | * Deletes all the files for a specific predicate
|
1157 | 1224 | *
|
@@ -1277,4 +1344,9 @@ public void finishUpdate(ConnectorSession session, ConnectorTableHandle tableHan
|
1277 | 1344 | handle.getSortOrder());
|
1278 | 1345 | finishWrite(session, outputTableHandle, fragments, UPDATE_AFTER);
|
1279 | 1346 | }
|
| 1347 | + |
| 1348 | + protected Optional<String> getDataLocationBasedOnWarehouseDataDir(SchemaTableName schemaTableName) |
| 1349 | + { |
| 1350 | + return Optional.empty(); |
| 1351 | + } |
1280 | 1352 | }
|
0 commit comments