use of org.apache.hadoop.hive.metastore.api.FieldSchema in project presto by prestodb.
the class BridgingHiveMetastore method renameColumn.
@Override
public void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(databaseName, tableName);
if (!source.isPresent()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
for (FieldSchema fieldSchema : table.getPartitionKeys()) {
if (fieldSchema.getName().equals(oldColumnName)) {
throw new PrestoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
}
}
for (FieldSchema fieldSchema : table.getSd().getCols()) {
if (fieldSchema.getName().equals(oldColumnName)) {
fieldSchema.setName(newColumnName);
}
}
alterTable(databaseName, tableName, table);
}
use of org.apache.hadoop.hive.metastore.api.FieldSchema in project drill by apache.
the class DrillHiveTable method getRowType.
@Override
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
List<RelDataType> typeList = Lists.newArrayList();
List<String> fieldNameList = Lists.newArrayList();
List<FieldSchema> hiveFields = hiveTable.getColumnListsCache().getColumns(0);
for (FieldSchema hiveField : hiveFields) {
fieldNameList.add(hiveField.getName());
typeList.add(getNullableRelDataTypeFromHiveType(typeFactory, TypeInfoUtils.getTypeInfoFromTypeString(hiveField.getType())));
}
for (FieldSchema field : hiveTable.getPartitionKeys()) {
fieldNameList.add(field.getName());
typeList.add(getNullableRelDataTypeFromHiveType(typeFactory, TypeInfoUtils.getTypeInfoFromTypeString(field.getType())));
}
return typeFactory.createStructType(typeList, fieldNameList);
}
use of org.apache.hadoop.hive.metastore.api.FieldSchema in project drill by apache.
the class TestColumnListCache method testPartitionColumnCaching.
@Test
public void testPartitionColumnCaching() {
ColumnListsCache cache = new ColumnListsCache();
List<FieldSchema> columns = Lists.newArrayList();
columns.add(new FieldSchema("f1", "int", null));
columns.add(new FieldSchema("f2", "int", null));
// sum of all indexes from cache
int indexSum = cache.addOrGet(columns);
indexSum += cache.addOrGet(columns);
List<FieldSchema> sameColumns = Lists.newArrayList(columns);
indexSum += cache.addOrGet(sameColumns);
List<FieldSchema> otherColumns = Lists.newArrayList();
otherColumns.add(new FieldSchema("f3", "int", null));
otherColumns.add(new FieldSchema("f4", "int", null));
// sum of all indexes from cache
int secondIndexSum = cache.addOrGet(otherColumns);
secondIndexSum += cache.addOrGet(otherColumns);
List<FieldSchema> sameOtherColumns = Lists.newArrayList();
sameOtherColumns.add(new FieldSchema("f3", "int", null));
sameOtherColumns.add(new FieldSchema("f4", "int", null));
secondIndexSum += cache.addOrGet(sameOtherColumns);
secondIndexSum += cache.addOrGet(Lists.newArrayList(sameOtherColumns));
secondIndexSum += cache.addOrGet(otherColumns);
secondIndexSum += cache.addOrGet(otherColumns);
indexSum += cache.addOrGet(sameColumns);
indexSum += cache.addOrGet(columns);
// added only two kinds of column lists
assertNull(cache.getColumns(3));
// sum of the indices of the first column list
assertEquals(0, indexSum);
assertEquals(6, secondIndexSum);
}
use of org.apache.hadoop.hive.metastore.api.FieldSchema in project drill by apache.
the class TestColumnListCache method testTableColumnsIndex.
@Test
public void testTableColumnsIndex() {
ColumnListsCache cache = new ColumnListsCache();
List<FieldSchema> columns = Lists.newArrayList();
columns.add(new FieldSchema("f1", "int", null));
columns.add(new FieldSchema("f2", "int", null));
assertEquals(0, cache.addOrGet(columns));
}
use of org.apache.hadoop.hive.metastore.api.FieldSchema in project drill by apache.
the class TestColumnListCache method testPartitionColumnListAccess.
@Test
public void testPartitionColumnListAccess() {
ColumnListsCache cache = new ColumnListsCache();
List<FieldSchema> columns = Lists.newArrayList();
columns.add(new FieldSchema("f1", "int", null));
columns.add(new FieldSchema("f2", "int", null));
cache.addOrGet(columns);
cache.addOrGet(columns);
columns.add(new FieldSchema("f3", "int", null));
cache.addOrGet(columns);
cache.addOrGet(columns);
columns.add(new FieldSchema("f4", "int", null));
cache.addOrGet(columns);
cache.addOrGet(columns);
assertEquals(columns, cache.getColumns(2));
}
Aggregations