|
21 | 21 | import static org.apache.iceberg.DistributionMode.HASH; |
22 | 22 | import static org.apache.iceberg.DistributionMode.NONE; |
23 | 23 | import static org.apache.iceberg.DistributionMode.RANGE; |
| 24 | +import static org.apache.iceberg.TableProperties.AVRO_COMPRESSION; |
| 25 | +import static org.apache.iceberg.TableProperties.AVRO_COMPRESSION_LEVEL; |
| 26 | +import static org.apache.iceberg.TableProperties.DELETE_AVRO_COMPRESSION; |
| 27 | +import static org.apache.iceberg.TableProperties.DELETE_AVRO_COMPRESSION_LEVEL; |
| 28 | +import static org.apache.iceberg.TableProperties.DELETE_ORC_COMPRESSION; |
| 29 | +import static org.apache.iceberg.TableProperties.DELETE_ORC_COMPRESSION_STRATEGY; |
| 30 | +import static org.apache.iceberg.TableProperties.DELETE_PARQUET_COMPRESSION; |
| 31 | +import static org.apache.iceberg.TableProperties.DELETE_PARQUET_COMPRESSION_LEVEL; |
| 32 | +import static org.apache.iceberg.TableProperties.ORC_COMPRESSION; |
| 33 | +import static org.apache.iceberg.TableProperties.ORC_COMPRESSION_STRATEGY; |
| 34 | +import static org.apache.iceberg.TableProperties.PARQUET_COMPRESSION; |
| 35 | +import static org.apache.iceberg.TableProperties.PARQUET_COMPRESSION_LEVEL; |
24 | 36 |
|
25 | 37 | import java.util.Locale; |
26 | 38 | import java.util.Map; |
@@ -373,4 +385,197 @@ public String branch() { |
373 | 385 |
|
374 | 386 | return branch; |
375 | 387 | } |
| 388 | + |
| 389 | + public Map<String, String> writeProperties() { |
| 390 | + Map<String, String> writeProperties = Maps.newHashMap(); |
| 391 | + writeProperties.putAll(dataWriteProperties()); |
| 392 | + writeProperties.putAll(deleteWriteProperties()); |
| 393 | + return writeProperties; |
| 394 | + } |
| 395 | + |
| 396 | + private Map<String, String> dataWriteProperties() { |
| 397 | + Map<String, String> writeProperties = Maps.newHashMap(); |
| 398 | + FileFormat dataFormat = dataFileFormat(); |
| 399 | + |
| 400 | + switch (dataFormat) { |
| 401 | + case PARQUET: |
| 402 | + writeProperties.put(PARQUET_COMPRESSION, parquetCompressionCodec()); |
| 403 | + String parquetCompressionLevel = parquetCompressionLevel(); |
| 404 | + if (parquetCompressionLevel != null) { |
| 405 | + writeProperties.put(PARQUET_COMPRESSION_LEVEL, parquetCompressionLevel); |
| 406 | + } |
| 407 | + break; |
| 408 | + |
| 409 | + case AVRO: |
| 410 | + writeProperties.put(AVRO_COMPRESSION, avroCompressionCodec()); |
| 411 | + String avroCompressionLevel = avroCompressionLevel(); |
| 412 | + if (avroCompressionLevel != null) { |
| 413 | + writeProperties.put(AVRO_COMPRESSION_LEVEL, avroCompressionLevel); |
| 414 | + } |
| 415 | + break; |
| 416 | + |
| 417 | + case ORC: |
| 418 | + writeProperties.put(ORC_COMPRESSION, orcCompressionCodec()); |
| 419 | + writeProperties.put(ORC_COMPRESSION_STRATEGY, orcCompressionStrategy()); |
| 420 | + break; |
| 421 | + |
| 422 | + default: |
| 423 | + // skip |
| 424 | + } |
| 425 | + |
| 426 | + return writeProperties; |
| 427 | + } |
| 428 | + |
| 429 | + private Map<String, String> deleteWriteProperties() { |
| 430 | + Map<String, String> writeProperties = Maps.newHashMap(); |
| 431 | + FileFormat deleteFormat = deleteFileFormat(); |
| 432 | + |
| 433 | + switch (deleteFormat) { |
| 434 | + case PARQUET: |
| 435 | + writeProperties.put(DELETE_PARQUET_COMPRESSION, deleteParquetCompressionCodec()); |
| 436 | + String deleteParquetCompressionLevel = deleteParquetCompressionLevel(); |
| 437 | + if (deleteParquetCompressionLevel != null) { |
| 438 | + writeProperties.put(DELETE_PARQUET_COMPRESSION_LEVEL, deleteParquetCompressionLevel); |
| 439 | + } |
| 440 | + break; |
| 441 | + |
| 442 | + case AVRO: |
| 443 | + writeProperties.put(DELETE_AVRO_COMPRESSION, deleteAvroCompressionCodec()); |
| 444 | + String deleteAvroCompressionLevel = deleteAvroCompressionLevel(); |
| 445 | + if (deleteAvroCompressionLevel != null) { |
| 446 | + writeProperties.put(DELETE_AVRO_COMPRESSION_LEVEL, deleteAvroCompressionLevel); |
| 447 | + } |
| 448 | + break; |
| 449 | + |
| 450 | + case ORC: |
| 451 | + writeProperties.put(DELETE_ORC_COMPRESSION, deleteOrcCompressionCodec()); |
| 452 | + writeProperties.put(DELETE_ORC_COMPRESSION_STRATEGY, deleteOrcCompressionStrategy()); |
| 453 | + break; |
| 454 | + |
| 455 | + default: |
| 456 | + // skip |
| 457 | + } |
| 458 | + |
| 459 | + return writeProperties; |
| 460 | + } |
| 461 | + |
| 462 | + private String parquetCompressionCodec() { |
| 463 | + return confParser |
| 464 | + .stringConf() |
| 465 | + .option(SparkWriteOptions.COMPRESSION_CODEC) |
| 466 | + .sessionConf(SparkSQLProperties.COMPRESSION_CODEC) |
| 467 | + .tableProperty(TableProperties.PARQUET_COMPRESSION) |
| 468 | + .defaultValue(TableProperties.PARQUET_COMPRESSION_DEFAULT) |
| 469 | + .parse(); |
| 470 | + } |
| 471 | + |
| 472 | + private String deleteParquetCompressionCodec() { |
| 473 | + return confParser |
| 474 | + .stringConf() |
| 475 | + .option(SparkWriteOptions.COMPRESSION_CODEC) |
| 476 | + .sessionConf(SparkSQLProperties.COMPRESSION_CODEC) |
| 477 | + .tableProperty(DELETE_PARQUET_COMPRESSION) |
| 478 | + .defaultValue(parquetCompressionCodec()) |
| 479 | + .parse(); |
| 480 | + } |
| 481 | + |
| 482 | + private String parquetCompressionLevel() { |
| 483 | + return confParser |
| 484 | + .stringConf() |
| 485 | + .option(SparkWriteOptions.COMPRESSION_LEVEL) |
| 486 | + .sessionConf(SparkSQLProperties.COMPRESSION_LEVEL) |
| 487 | + .tableProperty(TableProperties.PARQUET_COMPRESSION_LEVEL) |
| 488 | + .defaultValue(TableProperties.PARQUET_COMPRESSION_LEVEL_DEFAULT) |
| 489 | + .parseOptional(); |
| 490 | + } |
| 491 | + |
| 492 | + private String deleteParquetCompressionLevel() { |
| 493 | + return confParser |
| 494 | + .stringConf() |
| 495 | + .option(SparkWriteOptions.COMPRESSION_LEVEL) |
| 496 | + .sessionConf(SparkSQLProperties.COMPRESSION_LEVEL) |
| 497 | + .tableProperty(DELETE_PARQUET_COMPRESSION_LEVEL) |
| 498 | + .defaultValue(parquetCompressionLevel()) |
| 499 | + .parseOptional(); |
| 500 | + } |
| 501 | + |
| 502 | + private String avroCompressionCodec() { |
| 503 | + return confParser |
| 504 | + .stringConf() |
| 505 | + .option(SparkWriteOptions.COMPRESSION_CODEC) |
| 506 | + .sessionConf(SparkSQLProperties.COMPRESSION_CODEC) |
| 507 | + .tableProperty(TableProperties.AVRO_COMPRESSION) |
| 508 | + .defaultValue(TableProperties.AVRO_COMPRESSION_DEFAULT) |
| 509 | + .parse(); |
| 510 | + } |
| 511 | + |
| 512 | + private String deleteAvroCompressionCodec() { |
| 513 | + return confParser |
| 514 | + .stringConf() |
| 515 | + .option(SparkWriteOptions.COMPRESSION_CODEC) |
| 516 | + .sessionConf(SparkSQLProperties.COMPRESSION_CODEC) |
| 517 | + .tableProperty(DELETE_AVRO_COMPRESSION) |
| 518 | + .defaultValue(avroCompressionCodec()) |
| 519 | + .parse(); |
| 520 | + } |
| 521 | + |
| 522 | + private String avroCompressionLevel() { |
| 523 | + return confParser |
| 524 | + .stringConf() |
| 525 | + .option(SparkWriteOptions.COMPRESSION_LEVEL) |
| 526 | + .sessionConf(SparkSQLProperties.COMPRESSION_LEVEL) |
| 527 | + .tableProperty(TableProperties.AVRO_COMPRESSION_LEVEL) |
| 528 | + .defaultValue(TableProperties.AVRO_COMPRESSION_LEVEL_DEFAULT) |
| 529 | + .parseOptional(); |
| 530 | + } |
| 531 | + |
| 532 | + private String deleteAvroCompressionLevel() { |
| 533 | + return confParser |
| 534 | + .stringConf() |
| 535 | + .option(SparkWriteOptions.COMPRESSION_LEVEL) |
| 536 | + .sessionConf(SparkSQLProperties.COMPRESSION_LEVEL) |
| 537 | + .tableProperty(DELETE_AVRO_COMPRESSION_LEVEL) |
| 538 | + .defaultValue(avroCompressionLevel()) |
| 539 | + .parseOptional(); |
| 540 | + } |
| 541 | + |
| 542 | + private String orcCompressionCodec() { |
| 543 | + return confParser |
| 544 | + .stringConf() |
| 545 | + .option(SparkWriteOptions.COMPRESSION_CODEC) |
| 546 | + .sessionConf(SparkSQLProperties.COMPRESSION_CODEC) |
| 547 | + .tableProperty(TableProperties.ORC_COMPRESSION) |
| 548 | + .defaultValue(TableProperties.ORC_COMPRESSION_DEFAULT) |
| 549 | + .parse(); |
| 550 | + } |
| 551 | + |
| 552 | + private String deleteOrcCompressionCodec() { |
| 553 | + return confParser |
| 554 | + .stringConf() |
| 555 | + .option(SparkWriteOptions.COMPRESSION_CODEC) |
| 556 | + .sessionConf(SparkSQLProperties.COMPRESSION_CODEC) |
| 557 | + .tableProperty(DELETE_ORC_COMPRESSION) |
| 558 | + .defaultValue(orcCompressionCodec()) |
| 559 | + .parse(); |
| 560 | + } |
| 561 | + |
| 562 | + private String orcCompressionStrategy() { |
| 563 | + return confParser |
| 564 | + .stringConf() |
| 565 | + .option(SparkWriteOptions.COMPRESSION_STRATEGY) |
| 566 | + .sessionConf(SparkSQLProperties.COMPRESSION_STRATEGY) |
| 567 | + .tableProperty(TableProperties.ORC_COMPRESSION_STRATEGY) |
| 568 | + .defaultValue(TableProperties.ORC_COMPRESSION_STRATEGY_DEFAULT) |
| 569 | + .parse(); |
| 570 | + } |
| 571 | + |
| 572 | + private String deleteOrcCompressionStrategy() { |
| 573 | + return confParser |
| 574 | + .stringConf() |
| 575 | + .option(SparkWriteOptions.COMPRESSION_STRATEGY) |
| 576 | + .sessionConf(SparkSQLProperties.COMPRESSION_STRATEGY) |
| 577 | + .tableProperty(DELETE_ORC_COMPRESSION_STRATEGY) |
| 578 | + .defaultValue(orcCompressionStrategy()) |
| 579 | + .parse(); |
| 580 | + } |
376 | 581 | } |
0 commit comments