@Override public String getCaseSensitiveSchemaName(String caseInsensitiveSchemaName) { return getKeyspaceByCaseInsensitiveName(caseInsensitiveSchemaName).getName(); }
@Override public List<String> getCaseSensitiveSchemaNames() { ImmutableList.Builder<String> builder = ImmutableList.builder(); List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); for (KeyspaceMetadata meta : keyspaces) { builder.add(meta.getName()); } return builder.build(); }
private KeyspaceMetadata getKeyspaceByCaseInsensitiveName(String caseInsensitiveSchemaName) throws SchemaNotFoundException { List<KeyspaceMetadata> keyspaces = executeWithSession(session -> session.getCluster().getMetadata().getKeyspaces()); KeyspaceMetadata result = null; // Ensure that the error message is deterministic List<KeyspaceMetadata> sortedKeyspaces = Ordering.from(comparing(KeyspaceMetadata::getName)).immutableSortedCopy(keyspaces); for (KeyspaceMetadata keyspace : sortedKeyspaces) { if (keyspace.getName().equalsIgnoreCase(caseInsensitiveSchemaName)) { if (result != null) { throw new PrestoException( NOT_SUPPORTED, format("More than one keyspace has been found for the case insensitive schema name: %s -> (%s, %s)", caseInsensitiveSchemaName, result.getName(), keyspace.getName())); } result = keyspace; } } if (result == null) { throw new SchemaNotFoundException(caseInsensitiveSchemaName); } return result; }
private static AbstractTableMetadata getTableMetadata(KeyspaceMetadata keyspace, String caseInsensitiveTableName) { List<AbstractTableMetadata> tables = Stream.concat( keyspace.getTables().stream(), keyspace.getMaterializedViews().stream()) .filter(table -> table.getName().equalsIgnoreCase(caseInsensitiveTableName)) .collect(toImmutableList()); if (tables.size() == 0) { throw new TableNotFoundException(new SchemaTableName(keyspace.getName(), caseInsensitiveTableName)); } else if (tables.size() == 1) { return tables.get(0); } String tableNames = tables.stream() .map(AbstractTableMetadata::getName) .sorted() .collect(joining(", ")); throw new PrestoException( NOT_SUPPORTED, format("More than one table has been found for the case insensitive table name: %s -> (%s)", caseInsensitiveTableName, tableNames)); }
.collect(toList()); CassandraTableHandle tableHandle = new CassandraTableHandle(connectorId, tableMeta.getKeyspace().getName(), tableMeta.getName()); return new CassandraTable(tableHandle, sortedColumnHandles);
private CassandraColumnHandle buildColumnHandle(AbstractTableMetadata tableMetadata, ColumnMetadata columnMeta, boolean partitionKey, boolean clusteringKey, int ordinalPosition, boolean hidden) { CassandraType cassandraType = CassandraType.getCassandraType(columnMeta.getType().getName()); List<CassandraType> typeArguments = null; if (cassandraType != null && cassandraType.getTypeArgumentSize() > 0) { List<DataType> typeArgs = columnMeta.getType().getTypeArguments(); switch (cassandraType.getTypeArgumentSize()) { case 1: typeArguments = ImmutableList.of(CassandraType.getCassandraType(typeArgs.get(0).getName())); break; case 2: typeArguments = ImmutableList.of(CassandraType.getCassandraType(typeArgs.get(0).getName()), CassandraType.getCassandraType(typeArgs.get(1).getName())); break; default: throw new IllegalArgumentException("Invalid type arguments: " + typeArgs); } } boolean indexed = false; SchemaTableName schemaTableName = new SchemaTableName(tableMetadata.getKeyspace().getName(), tableMetadata.getName()); if (!isMaterializedView(schemaTableName)) { TableMetadata table = (TableMetadata) tableMetadata; for (IndexMetadata idx : table.getIndexes()) { if (idx.getTarget().equals(columnMeta.getName())) { indexed = true; break; } } } return new CassandraColumnHandle(connectorId, columnMeta.getName(), ordinalPosition, cassandraType, typeArguments, partitionKey, clusteringKey, indexed, hidden); }
@Override public boolean equals(Object other) { if (other == this) return true; if (other instanceof FunctionMetadata) { FunctionMetadata that = (FunctionMetadata) other; return this.keyspace.getName().equals(that.keyspace.getName()) && this.arguments.equals(that.arguments) && this.body.equals(that.body) && this.calledOnNullInput == that.calledOnNullInput && this.language.equals(that.language) && this.returnType.equals(that.returnType); } return false; }
@Override public int hashCode() { return MoreObjects.hashCode( this.keyspace.getName(), this.argumentTypes, this.finalFuncFullName, this.initCond, this.returnType, this.stateFuncFullName, this.stateType); } }
@Override public int hashCode() { return MoreObjects.hashCode( keyspace.getName(), arguments, body, calledOnNullInput, language, returnType); } }
public KeyspaceMetadataAssert hasName(String name) { assertThat(actual.getName()).isEqualTo(name); return this; }
private Map<String, UserType> buildUserTypes( KeyspaceMetadata keyspace, List<Row> udtRows, VersionNumber cassandraVersion, Cluster cluster) { Map<String, UserType> userTypes = new LinkedHashMap<String, UserType>(); if (udtRows != null) { for (Row udtRow : maybeSortUdts(udtRows, cluster, keyspace.getName())) { UserType type = UserType.build(keyspace, udtRow, cassandraVersion, cluster, userTypes); userTypes.put(type.getTypeName(), type); } } return userTypes; }
public AggregateMetadataAssert isInKeyspace(String keyspaceName) { assertThat(actual.getKeyspace().getName()).isEqualTo(keyspaceName); return this; }
public FunctionMetadataAssert isInKeyspace(String keyspaceName) { assertThat(actual.getKeyspace().getName()).isEqualTo(keyspaceName); return this; }
public TableMetadataAssert isInKeyspace(String keyspaceName) { assertThat(actual.getKeyspace().getName()).isEqualTo(keyspaceName); return this; }
Insert(TableMetadata table) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey()); }
Delete(TableMetadata table, List<Selector> columns) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey(), columns); }
Update(TableMetadata table) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey()); }
Truncate(TableMetadata table) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey()); }
Select(TableMetadata table, List<Object> columnNames, boolean isDistinct, boolean isJson) { this( Metadata.quoteIfNecessary(table.getKeyspace().getName()), Metadata.quoteIfNecessary(table.getName()), Arrays.asList(new Object[table.getPartitionKey().size()]), table.getPartitionKey(), columnNames, isDistinct, isJson); }
private void assertExists(String fetchName, String realName) { KeyspaceMetadata km = cluster().getMetadata().getKeyspace(fetchName); assertNotNull(km); assertEquals(realName, km.getName()); }