Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Bug fix in "DROP TABLE" when using S3 by resetting the tiledb context
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisStaratzis committed Oct 29, 2021
1 parent 89f2e2a commit c2c5ca2
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/main/java/com/facebook/presto/plugin/tiledb/TileDBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ public TileDBClient(TileDBConnectorId connectorId, TileDBConfig config)
this.config = requireNonNull(config, "config is null");
try {
// Create context
Config tileDBConfig = new Config();
if (config.getAwsAccessKeyId() != null && !config.getAwsAccessKeyId().isEmpty()
&& config.getAwsSecretAccessKey() != null && !config.getAwsSecretAccessKey().isEmpty()) {
tileDBConfig.set("vfs.s3.aws_access_key_id", config.getAwsAccessKeyId());
tileDBConfig.set("vfs.s3.aws_secret_access_key", config.getAwsSecretAccessKey());
}
ctx = new Context(tileDBConfig);
ctx = new Context(buildConfig());
//tileDBConfig.close();
}
catch (TileDBError tileDBError) {
Expand Down Expand Up @@ -110,11 +104,11 @@ public TileDBConfig getConfig()
}

/**
* Helper function to add a table to the catalog
*
* @param schema schema to add table to
* @param arrayUri uri of array/table
*/
* Helper function to add a table to the catalog
*
* @param schema schema to add table to
* @param arrayUri uri of array/table
*/
public TileDBTable addTableFromURI(Context localCtx, String schema, URI arrayUri)
{
return addTableFromURI(localCtx, schema, arrayUri, null, null);
Expand Down Expand Up @@ -242,6 +236,8 @@ public void rollbackCreateTable(TileDBOutputTableHandle handle)
try {
TileDBObject.remove(ctx, handle.getURI());
schemas.get(handle.getSchemaName()).remove(handle.getTableName());
ctx.close();
ctx = new Context(buildConfig());
}
catch (TileDBError tileDBError) {
throw new PrestoException(TileDBErrorCode.TILEDB_DROP_TABLE_ERROR, tileDBError);
Expand All @@ -254,12 +250,33 @@ public void dropTable(ConnectorSession session, TileDBTableHandle handle)
Context localCtx = buildContext(session);
TileDBObject.remove(localCtx, handle.getURI());
schemas.get(handle.getSchemaName()).remove(handle.getTableName());
ctx.close();
ctx = new Context(buildConfig());
}
catch (TileDBError tileDBError) {
throw new PrestoException(TileDBErrorCode.TILEDB_DROP_TABLE_ERROR, tileDBError);
}
}

public Config buildConfig()
{
try {
// Create context
Config tileDBConfig = new Config();
if (config.getAwsAccessKeyId() != null && !config.getAwsAccessKeyId().isEmpty()
&& config.getAwsSecretAccessKey() != null && !config.getAwsSecretAccessKey().isEmpty()) {
tileDBConfig.set("vfs.s3.aws_access_key_id", config.getAwsAccessKeyId());
tileDBConfig.set("vfs.s3.aws_secret_access_key", config.getAwsSecretAccessKey());
}
return tileDBConfig;
//tileDBConfig.close();
}
catch (TileDBError tileDBError) {
// Print stacktrace, this produces an error client side saying "internal error"
throw new TrinoException(TILEDB_CONTEXT_ERROR, tileDBError);
}
}

public Context buildContext(ConnectorSession session) throws TileDBError
{
Context localCtx = ctx;
Expand Down

0 comments on commit c2c5ca2

Please sign in to comment.