Skip to content

Commit

Permalink
Remove unused ordinalPosition from HiveColumnHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Oct 13, 2015
1 parent d3459a1 commit 5520f28
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class HiveColumnHandle

private final String clientId;
private final String name;
private final int ordinalPosition;
private final HiveType hiveType;
private final TypeSignature typeName;
private final int hiveColumnIndex;
Expand All @@ -44,16 +43,13 @@ public class HiveColumnHandle
public HiveColumnHandle(
@JsonProperty("clientId") String clientId,
@JsonProperty("name") String name,
@JsonProperty("ordinalPosition") int ordinalPosition,
@JsonProperty("hiveType") HiveType hiveType,
@JsonProperty("typeSignature") TypeSignature typeSignature,
@JsonProperty("hiveColumnIndex") int hiveColumnIndex,
@JsonProperty("partitionKey") boolean partitionKey)
{
this.clientId = requireNonNull(clientId, "clientId is null");
this.name = requireNonNull(name, "name is null");
checkArgument(ordinalPosition >= 0, "ordinalPosition is negative");
this.ordinalPosition = ordinalPosition;
checkArgument(hiveColumnIndex >= 0 || partitionKey, "hiveColumnIndex is negative");
this.hiveColumnIndex = hiveColumnIndex;
this.hiveType = requireNonNull(hiveType, "hiveType is null");
Expand All @@ -73,12 +69,6 @@ public String getName()
return name;
}

@JsonProperty
public int getOrdinalPosition()
{
return ordinalPosition;
}

@JsonProperty
public HiveType getHiveType()
{
Expand Down Expand Up @@ -137,7 +127,6 @@ public String toString()
return toStringHelper(this)
.add("clientId", clientId)
.add("name", name)
.add("ordinalPosition", ordinalPosition)
.add("hiveType", hiveType)
.add("hiveColumnIndex", hiveColumnIndex)
.add("partitionKey", partitionKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,6 @@ private static List<HiveColumnHandle> getColumnHandles(String connectorId, Conne
columnHandles.add(new HiveColumnHandle(
connectorId,
column.getName(),
ordinal,
toHiveType(column.getType()),
column.getType().getTypeSignature(),
ordinal,
Expand All @@ -1289,7 +1288,6 @@ private static List<HiveColumnHandle> getColumnHandles(String connectorId, Conne
columnHandles.add(new HiveColumnHandle(
connectorId,
SAMPLE_WEIGHT_COLUMN_NAME,
ordinal,
toHiveType(BIGINT),
BIGINT.getTypeSignature(),
ordinal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public HivePartitionResult getPartitions(ConnectorSession session, HiveMetastore
return new HivePartitionResult(ImmutableList.of(new HivePartition(tableName, compactEffectivePredicate, bucket)), effectivePredicate);
}

List<HiveColumnHandle> partitionColumns = getPartitionKeyColumnHandles(connectorId, table, 0);
List<HiveColumnHandle> partitionColumns = getPartitionKeyColumnHandles(connectorId, table);
List<String> partitionNames = getFilteredPartitionNames(metastore, tableName, partitionColumns, effectivePredicate);

// do a final pass to filter based on fields that could not be used to filter the partitions
Expand Down
12 changes: 5 additions & 7 deletions presto-hive/src/main/java/com/facebook/presto/hive/HiveUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,27 +519,25 @@ public static List<HiveColumnHandle> hiveColumnHandles(String connectorId, Table
TypeInfo typeInfo = getTypeInfoFromTypeString(field.getType());
if (HiveType.isSupportedType(typeInfo)) {
HiveType hiveType = toHiveType(typeInfo);
columns.add(new HiveColumnHandle(connectorId, field.getName(), hiveColumnIndex, hiveType, hiveType.getTypeSignature(), hiveColumnIndex, false));
columns.add(new HiveColumnHandle(connectorId, field.getName(), hiveType, hiveType.getTypeSignature(), hiveColumnIndex, false));
}
hiveColumnIndex++;
}

// add the partition keys last (like Hive does)
columns.addAll(getPartitionKeyColumnHandles(connectorId, table, hiveColumnIndex));
columns.addAll(getPartitionKeyColumnHandles(connectorId, table));

return columns.build();
}

public static List<HiveColumnHandle> getPartitionKeyColumnHandles(String connectorId, Table table, int startOrdinal)
public static List<HiveColumnHandle> getPartitionKeyColumnHandles(String connectorId, Table table)
{
ImmutableList.Builder<HiveColumnHandle> columns = ImmutableList.builder();

List<FieldSchema> partitionKeys = table.getPartitionKeys();
for (int i = 0; i < partitionKeys.size(); i++) {
FieldSchema field = partitionKeys.get(i);

for (FieldSchema field : partitionKeys) {
HiveType hiveType = HiveType.valueOf(field.getType());
columns.add(new HiveColumnHandle(connectorId, field.getName(), startOrdinal + i, hiveType, HiveType.valueOf(field.getType()).getTypeSignature(), -1, true));
columns.add(new HiveColumnHandle(connectorId, field.getName(), hiveType, HiveType.valueOf(field.getType()).getTypeSignature(), -1, true));
}

return columns.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ protected void setupHive(String connectorId, String databaseName, String timeZon
ImmutableList.of(new HivePartition(invalidTable, TupleDomain.<HiveColumnHandle>all(), "unknown", ImmutableMap.of(), Optional.empty())));
emptyTableLayoutHandle = new HiveTableLayoutHandle(invalidClientId, ImmutableList.of());

dsColumn = new HiveColumnHandle(connectorId, "ds", 0, HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), -1, true);
fileFormatColumn = new HiveColumnHandle(connectorId, "file_format", 1, HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), -1, true);
dummyColumn = new HiveColumnHandle(connectorId, "dummy", 2, HIVE_INT, parseTypeSignature(StandardTypes.BIGINT), -1, true);
intColumn = new HiveColumnHandle(connectorId, "t_int", 0, HIVE_INT, parseTypeSignature(StandardTypes.BIGINT), -1, true);
invalidColumnHandle = new HiveColumnHandle(connectorId, INVALID_COLUMN, 0, HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), 0, false);
dsColumn = new HiveColumnHandle(connectorId, "ds", HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), -1, true);
fileFormatColumn = new HiveColumnHandle(connectorId, "file_format", HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), -1, true);
dummyColumn = new HiveColumnHandle(connectorId, "dummy", HIVE_INT, parseTypeSignature(StandardTypes.BIGINT), -1, true);
intColumn = new HiveColumnHandle(connectorId, "t_int", HIVE_INT, parseTypeSignature(StandardTypes.BIGINT), -1, true);
invalidColumnHandle = new HiveColumnHandle(connectorId, INVALID_COLUMN, HIVE_STRING, parseTypeSignature(StandardTypes.VARCHAR), 0, false);

insertTableDestination = new SchemaTableName(database, "presto_insert_destination");
insertTablePartitionedDestination = new SchemaTableName(database, "presto_insert_destination_partitioned");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected List<HiveColumnHandle> getColumnHandles(List<TestColumn> testColumns)
int columnIndex = testColumn.isPartitionKey() ? -1 : nextHiveColumnIndex++;

HiveType hiveType = HiveType.valueOf(testColumn.getObjectInspector().getTypeName());
columns.add(new HiveColumnHandle("client_id", testColumn.getName(), i, hiveType, hiveType.getTypeSignature(), columnIndex, testColumn.isPartitionKey()));
columns.add(new HiveColumnHandle("client_id", testColumn.getName(), hiveType, hiveType.getTypeSignature(), columnIndex, testColumn.isPartitionKey()));
}
return columns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,6 @@ private static List<HiveColumnHandle> getHiveColumnHandles(TpchColumn<?>... tpch
HiveType hiveType = HiveType.valueOf(inspector.getTypeName());
columns.add(new HiveColumnHandle("test",
column.getColumnName(),
ordinal,
hiveType,
hiveType.getTypeSignature(),
ordinal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ public class TestHiveColumnHandle
@Test
public void testRoundTrip()
{
HiveColumnHandle expected = new HiveColumnHandle("client", "name", 42, HiveType.HIVE_FLOAT, parseTypeSignature(StandardTypes.DOUBLE), 88, true);
HiveColumnHandle expected = new HiveColumnHandle("client", "name", HiveType.HIVE_FLOAT, parseTypeSignature(StandardTypes.DOUBLE), 88, true);

String json = codec.toJson(expected);
HiveColumnHandle actual = codec.fromJson(json);

assertEquals(actual.getClientId(), expected.getClientId());
assertEquals(actual.getName(), expected.getName());
assertEquals(actual.getOrdinalPosition(), expected.getOrdinalPosition());
assertEquals(actual.getHiveType(), expected.getHiveType());
assertEquals(actual.getHiveColumnIndex(), expected.getHiveColumnIndex());
assertEquals(actual.isPartitionKey(), expected.isPartitionKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class TestJsonHiveHandles
private static final Map<String, Object> COLUMN_HANDLE_AS_MAP = ImmutableMap.<String, Object>builder()
.put("clientId", "hive")
.put("name", "column")
.put("ordinalPosition", 42)
.put("hiveType", "float")
.put("typeSignature", "double")
.put("hiveColumnIndex", -1)
Expand Down Expand Up @@ -77,7 +76,7 @@ public void testTableHandleDeserialize()
public void testColumnHandleSerialize()
throws Exception
{
HiveColumnHandle columnHandle = new HiveColumnHandle("hive", "column", 42, HiveType.HIVE_FLOAT, parseTypeSignature(StandardTypes.DOUBLE), -1, true);
HiveColumnHandle columnHandle = new HiveColumnHandle("hive", "column", HiveType.HIVE_FLOAT, parseTypeSignature(StandardTypes.DOUBLE), -1, true);

assertTrue(objectMapper.canSerialize(HiveColumnHandle.class));
String json = objectMapper.writeValueAsString(columnHandle);
Expand All @@ -93,7 +92,6 @@ public void testColumnHandleDeserialize()
HiveColumnHandle columnHandle = objectMapper.readValue(json, HiveColumnHandle.class);

assertEquals(columnHandle.getName(), "column");
assertEquals(columnHandle.getOrdinalPosition(), 42);
assertEquals(columnHandle.getHiveType(), HiveType.HIVE_FLOAT);
assertEquals(columnHandle.getHiveColumnIndex(), -1);
assertEquals(columnHandle.isPartitionKey(), true);
Expand Down

0 comments on commit 5520f28

Please sign in to comment.