Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor code cleanup in Hive/Delta #15303

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public static TypeInfo translate(Type type)
if (DOUBLE.equals(type)) {
return HIVE_DOUBLE.getTypeInfo();
}
if (type instanceof VarcharType) {
VarcharType varcharType = (VarcharType) type;
if (type instanceof VarcharType varcharType) {
if (varcharType.isUnbounded()) {
return HIVE_STRING.getTypeInfo();
}
Expand All @@ -106,8 +105,7 @@ public static TypeInfo translate(Type type)
}
throw new TrinoException(NOT_SUPPORTED, format("Unsupported Hive type: %s. Supported VARCHAR types: VARCHAR(<=%d), VARCHAR.", type, HiveVarchar.MAX_VARCHAR_LENGTH));
}
if (type instanceof CharType) {
CharType charType = (CharType) type;
if (type instanceof CharType charType) {
int charLength = charType.getLength();
if (charLength <= HiveChar.MAX_CHAR_LENGTH) {
return getCharTypeInfo(charLength);
Expand All @@ -129,8 +127,7 @@ public static TypeInfo translate(Type type)
verify(((TimestampType) type).getPrecision() == 3, "Unsupported type: %s", type);
return HIVE_TIMESTAMP.getTypeInfo();
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
return new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale());
}
if (isArrayType(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public boolean equals(Object o)
if (this == o) {
return true;
}
if (!(o instanceof DeltaLakeInputInfo)) {
if (!(o instanceof DeltaLakeInputInfo that)) {
return false;
}
DeltaLakeInputInfo that = (DeltaLakeInputInfo) o;
return partitioned == that.partitioned;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ private static Object toJsonValue(Type type, @Nullable Object value)
if (type == DOUBLE) {
return value;
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
if (decimalType.isShort()) {
return Decimals.toString((long) value, decimalType.getScale());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ private static Optional<String> serializeSupportedPrimitiveType(Type type)
if (type instanceof VarcharType) {
return Optional.of("string");
}
if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
if (type instanceof DecimalType decimalType) {
return Optional.of(String.format("decimal(%s,%s)", decimalType.getPrecision(), decimalType.getScale()));
}
return Optional.ofNullable(PRIMITIVE_TYPE_MAPPING.get(type));
Expand Down Expand Up @@ -288,14 +287,12 @@ private static void validateStructuralType(Optional<Type> rootType, Type type)
validateType(rootType, ((ArrayType) type).getElementType());
}

if (type instanceof MapType) {
MapType mapType = (MapType) type;
if (type instanceof MapType mapType) {
validateType(rootType, mapType.getKeyType());
validateType(rootType, mapType.getValueType());
}

if (type instanceof RowType) {
RowType rowType = (RowType) type;
if (type instanceof RowType rowType) {
rowType.getFields().forEach(field -> validateType(rootType, field.getType()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ public RowType getAddEntryType(MetadataEntry metadataEntry, boolean requireWrite

private static RowType.Field buildNullCountType(Optional<String> columnName, Type columnType)
{
if (columnType instanceof RowType) {
RowType rowType = (RowType) columnType;
if (columnType instanceof RowType rowType) {
if (columnName.isPresent()) {
return RowType.field(
columnName.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,7 @@ private Optional<Map<String, Object>> makeComparableStatistics(Optional<Map<Stri
ImmutableMap.Builder<String, Object> comparableStats = ImmutableMap.builder();
for (String key : stats.keySet()) {
Object statsValue = stats.get(key);
if (statsValue instanceof RowBlock) {
RowBlock rowBlock = (RowBlock) statsValue;
if (statsValue instanceof RowBlock rowBlock) {
ColumnarRow columnarRow = toColumnarRow(rowBlock);
int size = columnarRow.getFieldCount();
ImmutableList<Long> logicalSizes = IntStream.range(0, size)
Expand All @@ -464,8 +463,8 @@ private Optional<Map<String, Object>> makeComparableStatistics(Optional<Map<Stri
.collect(toImmutableList());
comparableStats.put(key, logicalSizes);
}
else if (statsValue instanceof Slice) {
comparableStats.put(key, ((Slice) statsValue).toStringUtf8());
else if (statsValue instanceof Slice slice) {
comparableStats.put(key, slice.toStringUtf8());
}
else {
comparableStats.put(key, statsValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,23 @@ public static HiveCompressionCodec selectCompressionCodec(HiveCompressionOption

private static HiveCompressionCodec selectCompressionCodec(HiveCompressionOption compressionOption)
{
switch (compressionOption) {
case NONE:
return HiveCompressionCodec.NONE;
case SNAPPY:
return HiveCompressionCodec.SNAPPY;
case LZ4:
return HiveCompressionCodec.LZ4;
case ZSTD:
return HiveCompressionCodec.ZSTD;
case GZIP:
return HiveCompressionCodec.GZIP;
}
throw new IllegalArgumentException("Unknown compressionOption " + compressionOption);
return switch (compressionOption) {
case NONE -> HiveCompressionCodec.NONE;
case SNAPPY -> HiveCompressionCodec.SNAPPY;
case LZ4 -> HiveCompressionCodec.LZ4;
case ZSTD -> HiveCompressionCodec.ZSTD;
case GZIP -> HiveCompressionCodec.GZIP;
};
}

private static HiveCompressionCodec selectCompressionCodecForUnknownStorageFormat(HiveCompressionOption compressionOption)
{
switch (compressionOption) {
case NONE:
return HiveCompressionCodec.NONE;
case SNAPPY:
return HiveCompressionCodec.SNAPPY;
case LZ4:
return HiveCompressionCodec.LZ4;
case ZSTD:
return HiveCompressionCodec.ZSTD;
case GZIP:
return HiveCompressionCodec.GZIP;
}
throw new IllegalArgumentException("Unknown compressionOption " + compressionOption);
return switch (compressionOption) {
case NONE -> HiveCompressionCodec.NONE;
case SNAPPY -> HiveCompressionCodec.SNAPPY;
case LZ4 -> HiveCompressionCodec.LZ4;
case ZSTD -> HiveCompressionCodec.ZSTD;
case GZIP -> HiveCompressionCodec.GZIP;
};
}
}