use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class HiveCoercionRecordCursor method createCoercer.
private static Coercer createCoercer(TypeManager typeManager, HiveType fromHiveType, HiveType toHiveType) {
Type fromType = typeManager.getType(fromHiveType.getTypeSignature());
Type toType = typeManager.getType(toHiveType.getTypeSignature());
if (toType instanceof VarcharType && (fromHiveType.equals(HIVE_BYTE) || fromHiveType.equals(HIVE_SHORT) || fromHiveType.equals(HIVE_INT) || fromHiveType.equals(HIVE_LONG))) {
return new IntegerNumberToVarcharCoercer();
} else if (fromType instanceof VarcharType && (toHiveType.equals(HIVE_BYTE) || toHiveType.equals(HIVE_SHORT) || toHiveType.equals(HIVE_INT) || toHiveType.equals(HIVE_LONG))) {
return new VarcharToIntegerNumberCoercer(toHiveType);
} else if (fromHiveType.equals(HIVE_BYTE) && toHiveType.equals(HIVE_SHORT) || toHiveType.equals(HIVE_INT) || toHiveType.equals(HIVE_LONG)) {
return new IntegerNumberUpscaleCoercer();
} else if (fromHiveType.equals(HIVE_SHORT) && toHiveType.equals(HIVE_INT) || toHiveType.equals(HIVE_LONG)) {
return new IntegerNumberUpscaleCoercer();
} else if (fromHiveType.equals(HIVE_INT) && toHiveType.equals(HIVE_LONG)) {
return new IntegerNumberUpscaleCoercer();
} else if (fromHiveType.equals(HIVE_FLOAT) && toHiveType.equals(HIVE_DOUBLE)) {
return new FloatToDoubleCoercer();
}
throw new PrestoException(NOT_SUPPORTED, format("Unsupported coercion from %s to %s", fromHiveType, toHiveType));
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class HiveLocationService method forNewTable.
@Override
public LocationHandle forNewTable(SemiTransactionalHiveMetastore metastore, String user, String queryId, String schemaName, String tableName) {
Path targetPath = getTableDefaultLocation(user, metastore, hdfsEnvironment, schemaName, tableName);
// verify the target directory for the table
if (pathExists(user, hdfsEnvironment, targetPath)) {
throw new PrestoException(HIVE_PATH_ALREADY_EXISTS, format("Target directory for table '%s.%s' already exists: %s", schemaName, tableName, targetPath));
}
Path writePath;
if (shouldUseTemporaryDirectory(user, targetPath)) {
writePath = createTemporaryPath(user, hdfsEnvironment, targetPath);
} else {
writePath = targetPath;
}
return new LocationHandle(targetPath, Optional.of(writePath), false);
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class HiveMetadata method writeEmptyFile.
private static void writeEmptyFile(Path target, JobConf conf, Properties properties, String serDe, String outputFormatName) {
// Some serializers such as Avro set a property in the schema.
initializeSerializer(conf, properties, serDe);
// The code below is not a try with resources because RecordWriter is not Closeable.
FileSinkOperator.RecordWriter recordWriter = HiveWriteUtils.createRecordWriter(target, conf, properties, outputFormatName);
try {
recordWriter.close(false);
} catch (IOException e) {
throw new PrestoException(HIVE_WRITER_CLOSE_ERROR, "Error write empty file to Hive", e);
}
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class HiveUtil method getPartitionKeyColumnHandles.
public static List<HiveColumnHandle> getPartitionKeyColumnHandles(String connectorId, Table table) {
ImmutableList.Builder<HiveColumnHandle> columns = ImmutableList.builder();
List<Column> partitionKeys = table.getPartitionColumns();
for (Column field : partitionKeys) {
HiveType hiveType = field.getType();
if (!hiveType.isSupportedType()) {
throw new PrestoException(NOT_SUPPORTED, format("Unsupported Hive type %s found in partition keys of table %s.%s", hiveType, table.getDatabaseName(), table.getTableName()));
}
columns.add(new HiveColumnHandle(connectorId, field.getName(), hiveType, hiveType.getTypeSignature(), -1, PARTITION_KEY, field.getComment()));
}
return columns.build();
}
use of com.facebook.presto.spi.PrestoException in project presto by prestodb.
the class HiveMetadata method getTableMetadata.
private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName) {
Optional<Table> table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
if (!table.isPresent() || table.get().getTableType().equals(TableType.VIRTUAL_VIEW.name())) {
throw new TableNotFoundException(tableName);
}
Function<HiveColumnHandle, ColumnMetadata> metadataGetter = columnMetadataGetter(table.get(), typeManager);
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (HiveColumnHandle columnHandle : hiveColumnHandles(connectorId, table.get())) {
columns.add(metadataGetter.apply(columnHandle));
}
ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
if (table.get().getTableType().equals(EXTERNAL_TABLE.name())) {
properties.put(EXTERNAL_LOCATION_PROPERTY, table.get().getStorage().getLocation());
}
try {
HiveStorageFormat format = extractHiveStorageFormat(table.get());
properties.put(STORAGE_FORMAT_PROPERTY, format);
} catch (PrestoException ignored) {
// todo fail if format is not known
}
List<String> partitionedBy = table.get().getPartitionColumns().stream().map(Column::getName).collect(toList());
if (!partitionedBy.isEmpty()) {
properties.put(PARTITIONED_BY_PROPERTY, partitionedBy);
}
Optional<HiveBucketProperty> bucketProperty = table.get().getStorage().getBucketProperty();
if (bucketProperty.isPresent()) {
properties.put(BUCKET_COUNT_PROPERTY, bucketProperty.get().getBucketCount());
properties.put(BUCKETED_BY_PROPERTY, bucketProperty.get().getBucketedBy());
}
properties.putAll(tableParameterCodec.decode(table.get().getParameters()));
return new ConnectorTableMetadata(tableName, columns.build(), properties.build());
}
Aggregations