Skip to content

Commit

Permalink
Use switch expression in IcebergFileFormat
Browse files Browse the repository at this point in the history
Not just plain refactor, but should be side effect free in practice.
  • Loading branch information
findepi committed Jan 30, 2024
1 parent c8c14ba commit 7e62f24
Showing 1 changed file with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
*/
package io.trino.plugin.iceberg;

import com.google.common.base.VerifyException;
import io.trino.spi.TrinoException;
import org.apache.iceberg.FileFormat;

import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;

public enum IcebergFileFormat
{
ORC,
Expand All @@ -28,28 +24,21 @@ public enum IcebergFileFormat

public FileFormat toIceberg()
{
switch (this) {
case ORC:
return FileFormat.ORC;
case PARQUET:
return FileFormat.PARQUET;
case AVRO:
return FileFormat.AVRO;
}
throw new VerifyException("Unhandled type: " + this);
return switch (this) {
case ORC -> FileFormat.ORC;
case PARQUET -> FileFormat.PARQUET;
case AVRO -> FileFormat.AVRO;
};
}

public static IcebergFileFormat fromIceberg(FileFormat format)
{
switch (format) {
case ORC:
return ORC;
case PARQUET:
return PARQUET;
case AVRO:
return AVRO;
default:
throw new TrinoException(NOT_SUPPORTED, "File format not supported for Iceberg: " + format);
}
return switch (format) {
case ORC -> ORC;
case PARQUET -> PARQUET;
case AVRO -> AVRO;
// Not used as a data file format
case METADATA -> throw new IllegalArgumentException("Unexpected METADATA file format");
};
}
}

0 comments on commit 7e62f24

Please sign in to comment.