Skip to content

Commit

Permalink
Allow specifying table location for Iceberg tables
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-fin authored and electrum committed Apr 8, 2020
1 parent 33a61a6 commit 67daaa9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.prestosql.plugin.base.classloader.ClassLoaderSafeSystemTable;
import io.prestosql.plugin.hive.HdfsEnvironment;
import io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext;
import io.prestosql.plugin.hive.HiveSchemaProperties;
import io.prestosql.plugin.hive.HiveWrittenPartitions;
import io.prestosql.plugin.hive.TableAlreadyExistsException;
import io.prestosql.plugin.hive.authentication.HiveIdentity;
Expand Down Expand Up @@ -82,12 +83,12 @@

import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.prestosql.plugin.hive.HiveSchemaProperties.getLocation;
import static io.prestosql.plugin.hive.util.HiveWriteUtils.getTableDefaultLocation;
import static io.prestosql.plugin.iceberg.DomainConverter.convertTupleDomainTypes;
import static io.prestosql.plugin.iceberg.ExpressionConverter.toIcebergExpression;
import static io.prestosql.plugin.iceberg.IcebergTableProperties.FILE_FORMAT_PROPERTY;
import static io.prestosql.plugin.iceberg.IcebergTableProperties.PARTITIONING_PROPERTY;
import static io.prestosql.plugin.iceberg.IcebergTableProperties.getLocation;
import static io.prestosql.plugin.iceberg.IcebergTableProperties.getPartitioning;
import static io.prestosql.plugin.iceberg.IcebergUtil.getColumns;
import static io.prestosql.plugin.iceberg.IcebergUtil.getDataPath;
Expand Down Expand Up @@ -253,7 +254,7 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
@Override
public void createSchema(ConnectorSession session, String schemaName, Map<String, Object> properties, PrestoPrincipal owner)
{
Optional<String> location = getLocation(properties).map(uri -> {
Optional<String> location = HiveSchemaProperties.getLocation(properties).map(uri -> {
try {
hdfsEnvironment.getFileSystem(new HdfsContext(session, schemaName), new Path(uri));
}
Expand Down Expand Up @@ -319,7 +320,10 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con

HdfsContext hdfsContext = new HdfsContext(session, schemaName, tableName);
HiveIdentity identity = new HiveIdentity(session);
String targetPath = getTableDefaultLocation(database, hdfsContext, hdfsEnvironment, schemaName, tableName).toString();
String targetPath = getLocation(tableMetadata.getProperties());
if (targetPath == null) {
targetPath = getTableDefaultLocation(database, hdfsContext, hdfsEnvironment, schemaName, tableName).toString();
}

TableOperations operations = new HiveTableOperations(metastore, hdfsEnvironment, hdfsContext, identity, schemaName, tableName, session.getUser(), targetPath);
if (operations.current() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@

import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.prestosql.spi.session.PropertyMetadata.enumProperty;
import static io.prestosql.spi.session.PropertyMetadata.stringProperty;
import static io.prestosql.spi.type.VarcharType.VARCHAR;
import static java.util.Locale.ENGLISH;

public class IcebergTableProperties
{
public static final String FILE_FORMAT_PROPERTY = "format";
public static final String PARTITIONING_PROPERTY = "partitioning";
public static final String LOCATION_PROPERTY = "location";

private final List<PropertyMetadata<?>> tableProperties;

Expand All @@ -57,6 +59,11 @@ public IcebergTableProperties(IcebergConfig icebergConfig)
.map(name -> ((String) name).toLowerCase(ENGLISH))
.collect(toImmutableList()),
value -> value))
.add(stringProperty(
LOCATION_PROPERTY,
"File system location URI for the table",
null,
false))
.build();
}

Expand All @@ -76,4 +83,9 @@ public static List<String> getPartitioning(Map<String, Object> tableProperties)
List<String> partitioning = (List<String>) tableProperties.get(PARTITIONING_PROPERTY);
return partitioning == null ? ImmutableList.of() : ImmutableList.copyOf(partitioning);
}

public static String getLocation(Map<String, Object> tableProperties)
{
return (String) tableProperties.get(LOCATION_PROPERTY);
}
}

0 comments on commit 67daaa9

Please sign in to comment.