From 367f1eb6e603043cef4f25c94cb0ae2eead03abd Mon Sep 17 00:00:00 2001 From: Eugene R Date: Mon, 18 Dec 2023 10:47:18 +0200 Subject: [PATCH] FMWK-290 Align Aerospike namespace naming with JDBC catalog (#56) --- .../aerospike/jdbc/AerospikeConnection.java | 8 +++---- .../jdbc/AerospikePreparedStatement.java | 6 +++--- .../aerospike/jdbc/AerospikeStatement.java | 8 +++---- .../jdbc/async/ScanQueryHandler.java | 6 +++--- .../async/SecondaryIndexQueryHandler.java | 2 +- .../aerospike/jdbc/model/AerospikeQuery.java | 21 +++---------------- .../jdbc/model/AerospikeSecondaryIndex.java | 2 +- .../jdbc/model/AerospikeSqlVisitor.java | 2 +- ...maTableName.java => CatalogTableName.java} | 20 +++++++++--------- .../com/aerospike/jdbc/model/DataColumn.java | 4 ++-- .../jdbc/model/DriverConfiguration.java | 18 ++++++++-------- .../jdbc/query/BaseQueryHandler.java | 2 +- .../jdbc/query/DeleteQueryHandler.java | 4 ++-- .../jdbc/query/InsertQueryHandler.java | 4 ++-- .../jdbc/query/SelectQueryHandler.java | 12 +++++------ .../jdbc/query/TruncateQueryHandler.java | 2 +- .../jdbc/query/UpdateQueryHandler.java | 4 ++-- .../jdbc/schema/AerospikeSchemaBuilder.java | 20 +++++++++--------- .../jdbc/schema/AerospikeSchemaCache.java | 14 ++++++------- .../jdbc/sql/AerospikeRecordResultSet.java | 4 ++-- .../jdbc/sql/AerospikeResultSetMetaData.java | 8 +++---- .../com/aerospike/jdbc/sql/BaseResultSet.java | 8 +++---- .../com/aerospike/jdbc/sql/ListRecordSet.java | 4 ++-- .../aerospike/jdbc/sql/type/BasicArray.java | 12 +++++------ .../com/aerospike/jdbc/QueryParserTest.java | 18 ++++++++-------- 25 files changed, 99 insertions(+), 114 deletions(-) rename src/main/java/com/aerospike/jdbc/model/{SchemaTableName.java => CatalogTableName.java} (57%) diff --git a/src/main/java/com/aerospike/jdbc/AerospikeConnection.java b/src/main/java/com/aerospike/jdbc/AerospikeConnection.java index 07e318b..9991179 100644 --- a/src/main/java/com/aerospike/jdbc/AerospikeConnection.java +++ b/src/main/java/com/aerospike/jdbc/AerospikeConnection.java @@ -35,7 +35,7 @@ public class AerospikeConnection implements Connection, SimpleWrapper { private final IAerospikeClient client; private final DatabaseMetadataBuilder metadataBuilder; private final AerospikeVersion aerospikeVersion; - private final AtomicReference schema = new AtomicReference<>(null); // namespace + private final AtomicReference catalog = new AtomicReference<>(null); private volatile boolean readOnly = false; private volatile Map> typeMap = emptyMap(); @@ -49,7 +49,7 @@ public AerospikeConnection(String url, Properties props) { client = config.parse(url); metadataBuilder = new DatabaseMetadataBuilder(config.getDriverPolicy()); aerospikeVersion = new AerospikeVersion(client); - schema.set(config.getSchema()); // namespace + catalog.set(config.getCatalog()); // namespace } @Override @@ -125,12 +125,12 @@ public void setReadOnly(boolean readOnly) throws SQLException { @Override public String getCatalog() { - return schema.get(); + return catalog.get(); } @Override public void setCatalog(String catalog) { - schema.set(catalog); + this.catalog.set(catalog); } @Override diff --git a/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java b/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java index 24331a8..0044937 100644 --- a/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java +++ b/src/main/java/com/aerospike/jdbc/AerospikePreparedStatement.java @@ -231,8 +231,8 @@ public ResultSetMetaData getMetaData() throws SQLException { AerospikeQuery query = parseQuery(prepareQueryString()); List columns = ((AerospikeDatabaseMetadata) connection.getMetaData()) .getSchemaBuilder() - .getSchema(query.getSchemaTable()); - return new AerospikeResultSetMetaData(query.getSchema(), query.getTable(), columns); + .getSchema(query.getCatalogTable()); + return new AerospikeResultSetMetaData(query.getCatalog(), query.getTable(), columns); } @Override @@ -265,7 +265,7 @@ public ParameterMetaData getParameterMetaData() throws SQLException { AerospikeQuery query = parseQuery(prepareQueryString()); List columns = ((AerospikeDatabaseMetadata) connection.getMetaData()) .getSchemaBuilder() - .getSchema(query.getSchemaTable()); + .getSchema(query.getCatalogTable()); return new SimpleParameterMetaData(columns); } diff --git a/src/main/java/com/aerospike/jdbc/AerospikeStatement.java b/src/main/java/com/aerospike/jdbc/AerospikeStatement.java index 2cf54e4..3157ca3 100644 --- a/src/main/java/com/aerospike/jdbc/AerospikeStatement.java +++ b/src/main/java/com/aerospike/jdbc/AerospikeStatement.java @@ -32,7 +32,7 @@ public class AerospikeStatement implements Statement, SimpleWrapper { protected final IAerospikeClient client; protected final AerospikeConnection connection; - protected String schema; + protected String catalog; protected ResultSet resultSet; protected int updateCount; @@ -42,7 +42,7 @@ public class AerospikeStatement implements Statement, SimpleWrapper { public AerospikeStatement(IAerospikeClient client, AerospikeConnection connection) { this.client = client; this.connection = connection; - this.schema = connection.getCatalog(); + this.catalog = connection.getCatalog(); } @Override @@ -67,8 +67,8 @@ protected AerospikeQuery parseQuery(String sql) throws SQLException { } catch (SqlParseException e) { query = AuxStatementParser.hack(sql); } - if (query.getSchema() == null) { - query.setSchema(schema); + if (query.getCatalog() == null) { + query.setCatalog(catalog); } return query; } diff --git a/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java b/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java index db7fd36..9ae472b 100644 --- a/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/async/ScanQueryHandler.java @@ -42,21 +42,21 @@ public RecordSet execute(ScanPolicy scanPolicy, AerospikeQuery query) { long maxRecords = scanPolicy.maxRecords; PartitionFilter filter = getPartitionFilter(query); while (isScanRequired(maxRecords)) { - client.scanPartitions(scanPolicy, filter, query.getSchema(), query.getSetName(), + client.scanPartitions(scanPolicy, filter, query.getCatalog(), query.getSetName(), callback, query.columnBins()); scanPolicy.maxRecords = maxRecords > 0 ? maxRecords - count : maxRecords; filter = PartitionFilter.id(++currentPartition); } listener.onSuccess(); } else { - client.scanAll(EventLoopProvider.getEventLoop(), listener, scanPolicy, query.getSchema(), + client.scanAll(EventLoopProvider.getEventLoop(), listener, scanPolicy, query.getCatalog(), query.getSetName(), query.columnBins()); } return listener.getRecordSet(); } private PartitionFilter getPartitionFilter(AerospikeQuery query) { - Key key = new Key(query.getSchema(), query.getSetName(), query.getOffset()); + Key key = new Key(query.getCatalog(), query.getSetName(), query.getOffset()); currentPartition = Partition.getPartitionId(key.digest); return PartitionFilter.after(key); } diff --git a/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java b/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java index cf9695b..8c12f41 100644 --- a/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/async/SecondaryIndexQueryHandler.java @@ -30,7 +30,7 @@ public RecordSet execute(QueryPolicy queryPolicy, AerospikeQuery query, statement.setRecordsPerSecond(client.getScanPolicyDefault().recordsPerSecond); statement.setIndexName(secondaryIndex.getIndexName()); - statement.setNamespace(query.getSchema()); + statement.setNamespace(query.getCatalog()); statement.setSetName(query.getTable()); statement.setBinNames(query.columnBins()); diff --git a/src/main/java/com/aerospike/jdbc/model/AerospikeQuery.java b/src/main/java/com/aerospike/jdbc/model/AerospikeQuery.java index f835d5b..ff832e7 100644 --- a/src/main/java/com/aerospike/jdbc/model/AerospikeQuery.java +++ b/src/main/java/com/aerospike/jdbc/model/AerospikeQuery.java @@ -31,7 +31,6 @@ public class AerospikeQuery { private static final String ASTERISK = "*"; private String catalog; - private String schema; private String table; private QueryType queryType; private Integer offset; @@ -59,15 +58,6 @@ public void setCatalog(String catalog) { this.catalog = catalog; } - public String getSchema() { - return schema; - } - - public void setSchema(String schema) { - this.catalog = schema; // TODO ? - this.schema = schema; - } - public String getTable() { return table; } @@ -75,13 +65,8 @@ public String getTable() { public void setTable(String table) { String[] spec = table.split("\\."); switch (spec.length) { - case 3: - this.catalog = spec[0]; - this.schema = spec[1]; - this.table = spec[2]; - break; case 2: - this.schema = spec[0]; + this.catalog = spec[0]; this.table = spec[1]; break; case 1: @@ -99,8 +84,8 @@ public String getSetName() { return table; } - public SchemaTableName getSchemaTable() { - return new SchemaTableName(schema, table); + public CatalogTableName getCatalogTable() { + return new CatalogTableName(catalog, table); } public QueryType getQueryType() { diff --git a/src/main/java/com/aerospike/jdbc/model/AerospikeSecondaryIndex.java b/src/main/java/com/aerospike/jdbc/model/AerospikeSecondaryIndex.java index 0afd14a..672570a 100644 --- a/src/main/java/com/aerospike/jdbc/model/AerospikeSecondaryIndex.java +++ b/src/main/java/com/aerospike/jdbc/model/AerospikeSecondaryIndex.java @@ -38,7 +38,7 @@ public class AerospikeSecondaryIndex { private final IndexType indexType; @Order(3) - @JsonProperty("schema_name") + @JsonProperty("catalog_name") private final String namespace; @Order(4) diff --git a/src/main/java/com/aerospike/jdbc/model/AerospikeSqlVisitor.java b/src/main/java/com/aerospike/jdbc/model/AerospikeSqlVisitor.java index c81fe42..9e1b511 100644 --- a/src/main/java/com/aerospike/jdbc/model/AerospikeSqlVisitor.java +++ b/src/main/java/com/aerospike/jdbc/model/AerospikeSqlVisitor.java @@ -78,7 +78,7 @@ public AerospikeQuery visit(SqlCall sqlCall) { query.setQueryType(QueryType.DROP_TABLE); } else if (sqlCall instanceof SqlDropSchema) { SqlDropSchema sql = (SqlDropSchema) sqlCall; - query.setSchema(requireNonNull(sql.name).toString()); + query.setCatalog(requireNonNull(sql.name).toString()); query.setQueryType(QueryType.DROP_SCHEMA); } else if (sqlCall instanceof SqlOrderBy) { SqlOrderBy sql = (SqlOrderBy) sqlCall; diff --git a/src/main/java/com/aerospike/jdbc/model/SchemaTableName.java b/src/main/java/com/aerospike/jdbc/model/CatalogTableName.java similarity index 57% rename from src/main/java/com/aerospike/jdbc/model/SchemaTableName.java rename to src/main/java/com/aerospike/jdbc/model/CatalogTableName.java index 7b5e6fa..5acb5c7 100644 --- a/src/main/java/com/aerospike/jdbc/model/SchemaTableName.java +++ b/src/main/java/com/aerospike/jdbc/model/CatalogTableName.java @@ -2,18 +2,18 @@ import java.util.Objects; -public class SchemaTableName { +public class CatalogTableName { - private final String schemaName; + private final String catalogName; private final String tableName; - public SchemaTableName(String schemaName, String tableName) { - this.schemaName = schemaName; + public CatalogTableName(String catalogName, String tableName) { + this.catalogName = catalogName; this.tableName = tableName; } - public String getSchemaName() { - return schemaName; + public String getCatalogName() { + return catalogName; } public String getTableName() { @@ -24,18 +24,18 @@ public String getTableName() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - SchemaTableName that = (SchemaTableName) o; - return Objects.equals(schemaName, that.schemaName) && + CatalogTableName that = (CatalogTableName) o; + return Objects.equals(catalogName, that.catalogName) && Objects.equals(tableName, that.tableName); } @Override public int hashCode() { - return Objects.hash(schemaName, tableName); + return Objects.hash(catalogName, tableName); } @Override public String toString() { - return String.format("%s(%s, %s)", getClass().getSimpleName(), schemaName, tableName); + return String.format("%s(%s, %s)", getClass().getSimpleName(), catalogName, tableName); } } diff --git a/src/main/java/com/aerospike/jdbc/model/DataColumn.java b/src/main/java/com/aerospike/jdbc/model/DataColumn.java index eafad23..28ea8d2 100644 --- a/src/main/java/com/aerospike/jdbc/model/DataColumn.java +++ b/src/main/java/com/aerospike/jdbc/model/DataColumn.java @@ -62,8 +62,8 @@ public int getType() { return type; } - public SchemaTableName getSchemaTableName() { - return new SchemaTableName(catalog, table); + public CatalogTableName getSchemaTableName() { + return new CatalogTableName(catalog, table); } @Override diff --git a/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java b/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java index 5592eb9..62e8da2 100644 --- a/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java +++ b/src/main/java/com/aerospike/jdbc/model/DriverConfiguration.java @@ -31,12 +31,12 @@ public final class DriverConfiguration { private static final String DEFAULT_AEROSPIKE_PORT = "3000"; - private static final Pattern AS_JDBC_URL = Pattern.compile("^jdbc:aerospike:(?://)?([^/?]+)"); - private static final Pattern AS_JDBC_SCHEMA = Pattern.compile("/([^?]+)"); + private static final Pattern AEROSPIKE_JDBC_URL = Pattern.compile("^jdbc:aerospike:(?://)?([^/?]+)"); + private static final Pattern AEROSPIKE_JDBC_CATALOG = Pattern.compile("/([^?]+)"); private final Map clientInfo = new ConcurrentHashMap<>(); private volatile IAerospikeClient client; - private volatile String schema; + private volatile String catalog; private volatile ClientPolicy clientPolicy; private volatile DriverPolicy driverPolicy; @@ -48,7 +48,7 @@ public DriverConfiguration(Properties props) { @SuppressWarnings("java:S2696") public IAerospikeClient parse(String url) { logger.info(() -> format("Parse URL: %s", url)); - schema = parseSchema(url); + catalog = parseCatalog(url); updateClientInfo(url); Value.UseBoolBin = Optional.ofNullable(clientInfo.get("useBoolBin")) @@ -113,7 +113,7 @@ private TlsPolicy buildTlsPolicy() { } private Host[] parseHosts(String url, final String tlsName) { - Matcher m = AS_JDBC_URL.matcher(url); + Matcher m = AEROSPIKE_JDBC_URL.matcher(url); if (!m.find()) { throw new IllegalArgumentException("Cannot parse URL " + url); } @@ -124,8 +124,8 @@ private Host[] parseHosts(String url, final String tlsName) { .toArray(Host[]::new); } - private String parseSchema(String url) { - Matcher m = AS_JDBC_SCHEMA.matcher(url); + private String parseCatalog(String url) { + Matcher m = AEROSPIKE_JDBC_CATALOG.matcher(url); return m.find() ? m.group(1) : null; } @@ -141,8 +141,8 @@ private void updateClientInfo(String url) { } } - public String getSchema() { - return schema; + public String getCatalog() { + return catalog; } public Properties getClientInfo() { diff --git a/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java index 23d152b..93a7534 100644 --- a/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/BaseQueryHandler.java @@ -48,7 +48,7 @@ protected Bin[] getBins(AerospikeQuery query) { } protected ListRecordSet emptyRecordSet(AerospikeQuery query) { - return new ListRecordSet(statement, query.getSchema(), query.getTable(), + return new ListRecordSet(statement, query.getCatalog(), query.getTable(), emptyList(), emptyList()); } diff --git a/src/main/java/com/aerospike/jdbc/query/DeleteQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/DeleteQueryHandler.java index 0467134..2e6102e 100644 --- a/src/main/java/com/aerospike/jdbc/query/DeleteQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/DeleteQueryHandler.java @@ -34,7 +34,7 @@ public Pair execute(AerospikeQuery query) { logger.info("DELETE primary key"); FutureDeleteListener listener = new FutureDeleteListener(keyObjects.size()); for (Object keyObject : keyObjects) { - Key key = new Key(query.getSchema(), query.getSetName(), Value.get(keyObject)); + Key key = new Key(query.getCatalog(), query.getSetName(), Value.get(keyObject)); try { client.delete(EventLoopProvider.getEventLoop(), listener, writePolicy, key); } catch (AerospikeException e) { @@ -49,7 +49,7 @@ public Pair execute(AerospikeQuery query) { ScanPolicy scanPolicy = policyBuilder.buildScanPolicy(query); scanPolicy.includeBinData = false; - client.scanAll(EventLoopProvider.getEventLoop(), listener, scanPolicy, query.getSchema(), + client.scanAll(EventLoopProvider.getEventLoop(), listener, scanPolicy, query.getCatalog(), query.getSetName()); final WritePolicy deletePolicy = policyBuilder.buildDeleteWritePolicy(); diff --git a/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java index fcd758e..af52ccd 100644 --- a/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/InsertQueryHandler.java @@ -49,7 +49,7 @@ public Pair putConsecutively(AerospikeQuery query) { @SuppressWarnings("unchecked") List values = (List) aerospikeRecord; Value recordKey = extractInsertKey(query, values); - Key key = new Key(query.getSchema(), query.getSetName(), recordKey); + Key key = new Key(query.getCatalog(), query.getSetName(), recordKey); Bin[] bins = buildBinArray(binNames, values); try { @@ -73,7 +73,7 @@ public Pair putBatch(AerospikeQuery query) { @SuppressWarnings("unchecked") List values = (List) aerospikeRecord; Value recordKey = extractInsertKey(query, values); - Key key = new Key(query.getSchema(), query.getSetName(), recordKey); + Key key = new Key(query.getCatalog(), query.getSetName(), recordKey); batchRecords.add( new BatchWrite( batchWritePolicy, diff --git a/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java index 4262efe..65a1158 100644 --- a/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/SelectQueryHandler.java @@ -54,7 +54,7 @@ public SelectQueryHandler(IAerospikeClient client, Statement statement) { @Override public Pair execute(AerospikeQuery query) { - columns = databaseMetadata.getSchemaBuilder().getSchema(query.getSchemaTable()); + columns = databaseMetadata.getSchemaBuilder().getSchema(query.getCatalogTable()); Collection keyObjects = query.getPrimaryKeys(); Optional sIndex = secondaryIndex(query); Pair result; @@ -74,7 +74,7 @@ private Pair executeCountQuery(AerospikeQuery query) { String countLabel = query.getColumns().get(0); int recordNumber; if (Objects.isNull(query.getPredicate())) { - recordNumber = getTableRecordsNumber(client, query.getSchema(), query.getTable()); + recordNumber = getTableRecordsNumber(client, query.getCatalog(), query.getTable()); } else { ScanPolicy policy = policyBuilder.buildScanNoBinDataPolicy(query); RecordSet recordSet = ScanQueryHandler.create(client, config.getDriverPolicy()) @@ -91,7 +91,7 @@ private Pair executeCountQuery(AerospikeQuery query) { recordSet.put(new KeyRecord(null, aeroRecord)); recordSet.close(); - columns = Collections.singletonList(new DataColumn(query.getSchema(), query.getTable(), + columns = Collections.singletonList(new DataColumn(query.getCatalog(), query.getTable(), Types.INTEGER, countLabel, countLabel)); return queryResult(recordSet, query); @@ -102,7 +102,7 @@ private Pair executeSelectByPrimaryKey(AerospikeQuery query, final BatchReadPolicy policy = policyBuilder.buildBatchReadPolicy(query); List batchReadList = keyObjects.stream() .map(k -> { - Key key = new Key(query.getSchema(), query.getSetName(), Value.get(k)); + Key key = new Key(query.getCatalog(), query.getSetName(), Value.get(k)); return new BatchRead(policy, key, true); }) .collect(Collectors.toList()); @@ -135,7 +135,7 @@ private Pair executeQuery(AerospikeQuery query, private Optional secondaryIndex(AerospikeQuery query) { if (aerospikeVersion.isSIndexSupported() && query.isIndexable()) { - Collection indexes = databaseMetadata.getSecondaryIndexes(query.getSchema()); + Collection indexes = databaseMetadata.getSecondaryIndexes(query.getCatalog()); List binNames = query.getPredicate().getBinNames(); if (!binNames.isEmpty() && indexes != null && !indexes.isEmpty()) { List indexList = indexes.stream() @@ -154,7 +154,7 @@ private Optional secondaryIndex(AerospikeQuery query) { } private Pair queryResult(RecordSet recordSet, AerospikeQuery query) { - return new Pair<>(new AerospikeRecordResultSet(recordSet, statement, query.getSchema(), + return new Pair<>(new AerospikeRecordResultSet(recordSet, statement, query.getCatalog(), query.getTable(), filterColumns(query)), -1); } diff --git a/src/main/java/com/aerospike/jdbc/query/TruncateQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/TruncateQueryHandler.java index fcd1563..86cbced 100644 --- a/src/main/java/com/aerospike/jdbc/query/TruncateQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/TruncateQueryHandler.java @@ -19,7 +19,7 @@ public TruncateQueryHandler(IAerospikeClient client, Statement statement) { @Override public Pair execute(AerospikeQuery query) { logger.info("TRUNCATE/DROP statement"); - client.truncate(null, query.getSchema(), query.getSetName(), null); + client.truncate(null, query.getCatalog(), query.getSetName(), null); return new Pair<>(emptyRecordSet(query), 1); } diff --git a/src/main/java/com/aerospike/jdbc/query/UpdateQueryHandler.java b/src/main/java/com/aerospike/jdbc/query/UpdateQueryHandler.java index 883719a..8c59afb 100644 --- a/src/main/java/com/aerospike/jdbc/query/UpdateQueryHandler.java +++ b/src/main/java/com/aerospike/jdbc/query/UpdateQueryHandler.java @@ -36,7 +36,7 @@ public Pair execute(AerospikeQuery query) { logger.info("UPDATE primary key"); FutureWriteListener listener = new FutureWriteListener(keyObjects.size()); for (Object keyObject : keyObjects) { - Key key = new Key(query.getSchema(), query.getSetName(), Value.get(keyObject)); + Key key = new Key(query.getCatalog(), query.getSetName(), Value.get(keyObject)); try { client.put(EventLoopProvider.getEventLoop(), listener, writePolicy, key, bins); } catch (AerospikeException e) { @@ -50,7 +50,7 @@ public Pair execute(AerospikeQuery query) { RecordSetRecordSequenceListener listener = new RecordSetRecordSequenceListener(config.getDriverPolicy()); ScanPolicy scanPolicy = policyBuilder.buildScanPolicy(query); scanPolicy.includeBinData = false; - client.scanAll(EventLoopProvider.getEventLoop(), listener, scanPolicy, query.getSchema(), + client.scanAll(EventLoopProvider.getEventLoop(), listener, scanPolicy, query.getCatalog(), query.getSetName()); final AtomicInteger count = new AtomicInteger(); diff --git a/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java b/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java index 370efec..69a2232 100644 --- a/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java +++ b/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaBuilder.java @@ -3,9 +3,9 @@ import com.aerospike.client.IAerospikeClient; import com.aerospike.client.Value; import com.aerospike.client.policy.ScanPolicy; +import com.aerospike.jdbc.model.CatalogTableName; import com.aerospike.jdbc.model.DataColumn; import com.aerospike.jdbc.model.DriverPolicy; -import com.aerospike.jdbc.model.SchemaTableName; import java.sql.Types; import java.time.Duration; @@ -32,9 +32,9 @@ public AerospikeSchemaBuilder(IAerospikeClient client, DriverPolicy driverPolicy scanMaxRecords = driverPolicy.getSchemaBuilderMaxRecords(); } - public List getSchema(SchemaTableName schemaTableName) { - return schemaCache.get(schemaTableName).orElseGet(() -> { - logger.info(() -> "Fetching SchemaTableName: " + schemaTableName); + public List getSchema(CatalogTableName catalogTableName) { + return schemaCache.get(catalogTableName).orElseGet(() -> { + logger.info(() -> "Fetching CatalogTableName: " + catalogTableName); final Map columnHandles = new TreeMap<>(String::compareToIgnoreCase); ScanPolicy policy = new ScanPolicy(client.getScanPolicyDefault()); policy.maxRecords = scanMaxRecords; @@ -42,13 +42,13 @@ public List getSchema(SchemaTableName schemaTableName) { // add record key column handler columnHandles.put(PRIMARY_KEY_COLUMN_NAME, new DataColumn( - schemaTableName.getSchemaName(), - schemaTableName.getTableName(), + catalogTableName.getCatalogName(), + catalogTableName.getTableName(), Types.VARCHAR, PRIMARY_KEY_COLUMN_NAME, PRIMARY_KEY_COLUMN_NAME)); - client.scanAll(policy, schemaTableName.getSchemaName(), toSet(schemaTableName.getTableName()), + client.scanAll(policy, catalogTableName.getCatalogName(), toSet(catalogTableName.getTableName()), (key, rec) -> { Map bins = rec.bins; if (bins != null) { @@ -56,15 +56,15 @@ public List getSchema(SchemaTableName schemaTableName) { logger.fine(() -> String.format("Bin: %s -> %s", k, value)); int t = getBinType(value); if (k != null && t != 0) { - columnHandles.put(k, new DataColumn(schemaTableName.getSchemaName(), - schemaTableName.getTableName(), t, k, k)); + columnHandles.put(k, new DataColumn(catalogTableName.getCatalogName(), + catalogTableName.getTableName(), t, k, k)); } }); } }); List columns = new ArrayList<>(columnHandles.values()); - schemaCache.put(schemaTableName, columns); + schemaCache.put(catalogTableName, columns); return columns; }); } diff --git a/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaCache.java b/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaCache.java index 9b5ac72..22f9917 100644 --- a/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaCache.java +++ b/src/main/java/com/aerospike/jdbc/schema/AerospikeSchemaCache.java @@ -1,7 +1,7 @@ package com.aerospike.jdbc.schema; +import com.aerospike.jdbc.model.CatalogTableName; import com.aerospike.jdbc.model.DataColumn; -import com.aerospike.jdbc.model.SchemaTableName; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -10,22 +10,22 @@ import java.util.Optional; public final class AerospikeSchemaCache - implements OptionalCache> { + implements OptionalCache> { - private final Cache> store; + private final Cache> store; public AerospikeSchemaCache(Duration ttl) { store = CacheBuilder.newBuilder().expireAfterWrite(ttl).build(); } @Override - public Optional> get(SchemaTableName schemaTableName) { - return Optional.ofNullable(store.getIfPresent(schemaTableName)); + public Optional> get(CatalogTableName catalogTableName) { + return Optional.ofNullable(store.getIfPresent(catalogTableName)); } @Override - public void put(SchemaTableName schemaTableName, List columns) { - store.put(schemaTableName, columns); + public void put(CatalogTableName catalogTableName, List columns) { + store.put(catalogTableName, columns); } @Override diff --git a/src/main/java/com/aerospike/jdbc/sql/AerospikeRecordResultSet.java b/src/main/java/com/aerospike/jdbc/sql/AerospikeRecordResultSet.java index a816d2e..0ef3337 100644 --- a/src/main/java/com/aerospike/jdbc/sql/AerospikeRecordResultSet.java +++ b/src/main/java/com/aerospike/jdbc/sql/AerospikeRecordResultSet.java @@ -22,11 +22,11 @@ public class AerospikeRecordResultSet extends BaseResultSet { public AerospikeRecordResultSet( RecordSet recordSet, Statement statement, - String schema, + String catalog, String table, List columns // columns list ) { - super(statement, schema, table, columns); + super(statement, catalog, table, columns); this.recordSet = recordSet; } diff --git a/src/main/java/com/aerospike/jdbc/sql/AerospikeResultSetMetaData.java b/src/main/java/com/aerospike/jdbc/sql/AerospikeResultSetMetaData.java index 065b1a0..1b0d93b 100644 --- a/src/main/java/com/aerospike/jdbc/sql/AerospikeResultSetMetaData.java +++ b/src/main/java/com/aerospike/jdbc/sql/AerospikeResultSetMetaData.java @@ -71,12 +71,12 @@ public class AerospikeResultSetMetaData implements ResultSetMetaData, SimpleWrap precisionByType.put(Types.TIMESTAMP_WITH_TIMEZONE, MAX_DATE_SIZE); } - private final String schema; + private final String catalog; private final String table; private final List columns; // has the order of the inferred schema - public AerospikeResultSetMetaData(String schema, String table, List columns) { - this.schema = schema; + public AerospikeResultSetMetaData(String catalog, String table, List columns) { + this.catalog = catalog; this.table = table; this.columns = Collections.unmodifiableList(columns); } @@ -167,7 +167,7 @@ public String getTableName(int column) throws SQLException { @Override public String getCatalogName(int column) throws SQLException { validateColumn(column); - return schema; + return catalog; } @Override diff --git a/src/main/java/com/aerospike/jdbc/sql/BaseResultSet.java b/src/main/java/com/aerospike/jdbc/sql/BaseResultSet.java index 6627718..396b3e4 100644 --- a/src/main/java/com/aerospike/jdbc/sql/BaseResultSet.java +++ b/src/main/java/com/aerospike/jdbc/sql/BaseResultSet.java @@ -19,7 +19,7 @@ public abstract class BaseResultSet implements ResultSet, IndexToLabelResultSet, UpdateResultSet, SimpleWrapper { - protected final String schema; + protected final String catalog; protected final String table; protected final List columns; private final Statement statement; @@ -30,12 +30,12 @@ public abstract class BaseResultSet implements ResultSet, protected boolean wasNull; private volatile boolean closed; - protected BaseResultSet(Statement statement, String schema, String table, List columns) { + protected BaseResultSet(Statement statement, String catalog, String table, List columns) { this.statement = statement; - this.schema = schema; + this.catalog = catalog; this.table = table; this.columns = Collections.unmodifiableList(columns); - this.metadata = new AerospikeResultSetMetaData(schema, table, columns); + this.metadata = new AerospikeResultSetMetaData(catalog, table, columns); } @Override diff --git a/src/main/java/com/aerospike/jdbc/sql/ListRecordSet.java b/src/main/java/com/aerospike/jdbc/sql/ListRecordSet.java index 0f1d850..806540e 100644 --- a/src/main/java/com/aerospike/jdbc/sql/ListRecordSet.java +++ b/src/main/java/com/aerospike/jdbc/sql/ListRecordSet.java @@ -23,9 +23,9 @@ public class ListRecordSet extends BaseResultSet> { private final Map nameToIndex; private List currentRecord = null; - public ListRecordSet(Statement statement, String schema, String table, List columns, + public ListRecordSet(Statement statement, String catalog, String table, List columns, Iterable> data) { - super(statement, schema, table, columns); + super(statement, catalog, table, columns); this.it = data.iterator(); nameToIndex = IntStream.range(0, columns.size()).boxed() .collect(toMap(i -> columns.get(i).getName(), i -> i)); diff --git a/src/main/java/com/aerospike/jdbc/sql/type/BasicArray.java b/src/main/java/com/aerospike/jdbc/sql/type/BasicArray.java index bcb8991..ce59ff9 100644 --- a/src/main/java/com/aerospike/jdbc/sql/type/BasicArray.java +++ b/src/main/java/com/aerospike/jdbc/sql/type/BasicArray.java @@ -24,7 +24,7 @@ public class BasicArray extends SerialArray { private final transient List columns; - private String schema; + private String catalog; public BasicArray(Array array, Map> map) throws SQLException { super(array, map); @@ -36,7 +36,7 @@ public BasicArray(Array array) throws SQLException { columns = columns(array.getBaseType()); } - public BasicArray(String schema, String baseTypeName, Object[] elements) throws SQLException { + public BasicArray(String catalog, String baseTypeName, Object[] elements) throws SQLException { super(new Array() { private final int baseType = ofNullable(SqlLiterals.sqlTypeByName.get(baseTypeName)) .orElseThrow(() -> new IllegalArgumentException(format("Unsupported array type %s", baseTypeName))); @@ -96,13 +96,13 @@ public void free() { throw new IllegalStateException(); } }); - this.schema = schema; + this.catalog = catalog; columns = columns(getBaseType()); } private List columns(int baseType) { - return asList(new DataColumn(schema, null, "INDEX", "INDEX").withType(Types.INTEGER), - new DataColumn(schema, null, "VALUE", "VALUE").withType(baseType)); + return asList(new DataColumn(catalog, null, "INDEX", "INDEX").withType(Types.INTEGER), + new DataColumn(catalog, null, "VALUE", "VALUE").withType(baseType)); } @Override @@ -127,6 +127,6 @@ public ResultSet getResultSet(long index, int count, Map> map) .skip(index) .map(e -> asList(counter.incrementAndGet(), e)) .collect(toList()); - return new ListRecordSet(null, schema, null, columns, data); + return new ListRecordSet(null, catalog, null, columns, data); } } diff --git a/src/test/java/com/aerospike/jdbc/QueryParserTest.java b/src/test/java/com/aerospike/jdbc/QueryParserTest.java index 08e9372..e4272b1 100644 --- a/src/test/java/com/aerospike/jdbc/QueryParserTest.java +++ b/src/test/java/com/aerospike/jdbc/QueryParserTest.java @@ -28,7 +28,7 @@ public void testSelectQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.SELECT); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertEquals(query.getColumns(), Arrays.asList("pkup_datetime", "vendor_id")); assertNotNull(query.getPredicate()); @@ -45,7 +45,7 @@ public void testSelectCountQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.SELECT); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertEquals(query.getColumns(), Collections.singletonList("COUNT(*)")); assertNotNull(query.getPredicate()); @@ -60,7 +60,7 @@ public void testUpdateQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.UPDATE); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertEquals(query.getColumns(), Collections.singletonList("archived")); assertEquals(query.getValues(), Collections.singletonList(true)); @@ -77,7 +77,7 @@ public void testInsertQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.INSERT); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertEquals(query.getColumns(), Arrays.asList("id", "cab_type", "trip_distance", "archived")); assertEquals(query.getValues().size(), 2); @@ -93,7 +93,7 @@ public void testDeleteQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.DELETE); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertNotNull(query.getPredicate()); } @@ -106,7 +106,7 @@ public void testDropTableQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.DROP_TABLE); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertNull(query.getPredicate()); } @@ -119,7 +119,7 @@ public void testDropSchemaQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.DROP_SCHEMA); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertNull(query.getTable()); assertNull(query.getPredicate()); } @@ -133,7 +133,7 @@ public void testSelectInQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.SELECT); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertNotNull(query.getPredicate()); assertEquals(query.getColumns(), Collections.singletonList("trip_distance")); @@ -148,7 +148,7 @@ public void testSelectBetweenQuery() throws SqlParseException { AerospikeQuery query = parsed.accept(new AerospikeSqlVisitor()); assertEquals(query.getQueryType(), QueryType.SELECT); - assertEquals(query.getSchema(), "test"); + assertEquals(query.getCatalog(), "test"); assertEquals(query.getTable(), "nyc-data"); assertNotNull(query.getPredicate()); assertEquals(query.getColumns(), Collections.singletonList("trip_distance"));