Java Code Examples for com.datastax.driver.core.KeyspaceMetadata#getTables()
The following examples show how to use
com.datastax.driver.core.KeyspaceMetadata#getTables() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraSession.java From presto with Apache License 2.0 | 5 votes |
public List<String> getCaseSensitiveTableNames(String caseInsensitiveSchemaName) throws SchemaNotFoundException { KeyspaceMetadata keyspace = getKeyspaceByCaseInsensitiveName(caseInsensitiveSchemaName); ImmutableList.Builder<String> builder = ImmutableList.builder(); for (TableMetadata table : keyspace.getTables()) { builder.add(table.getName()); } for (MaterializedViewMetadata materializedView : keyspace.getMaterializedViews()) { builder.add(materializedView.getName()); } return builder.build(); }
Example 2
Source File: Session.java From glowroot with Apache License 2.0 | 5 votes |
public Collection<TableMetadata> getTables() { KeyspaceMetadata keyspace = getKeyspace(); if (keyspace == null) { return ImmutableList.of(); } else { return keyspace.getTables(); } }
Example 3
Source File: DescribeKeySpaceAnyExecutor.java From Explorer with Apache License 2.0 | 5 votes |
/** * Execute when shCQL is DESCRIBE KEYSPACE anyvalue * @param metaData * @return table */ @Override public Table execute(Metadata metaData) { KeyspaceMetadata keySpaceMetada = metaData.getKeyspace(param); FunctionalList<TableMetadata,RowData> functionalList = new FunctionalList<>(new ArrayList<>(keySpaceMetada.getTables())); List<RowData> rows = functionalList.map(new TableMetadataToRowDataFunction()); rows.add(0,buildFirst(keySpaceMetada.toString())); return new Table(new ListUtils<String>().buildList(),rows); }
Example 4
Source File: KeyspaceTablestoRowData.java From Explorer with Apache License 2.0 | 5 votes |
/** * * @param keyspaceMetadata * @return ransform KeySpacetables to CellData with tableName */ @Override public RowData transform(KeyspaceMetadata keyspaceMetadata) { List<TableMetadata> tables = new ArrayList<>(keyspaceMetadata.getTables()); FunctionalList<TableMetadata,CellData> functional = new FunctionalList<>(tables); List<CellData> cells = new ListUtils<CellData>().buildList(new CellData(buildTable(keyspaceMetadata.getName(),functional))); return new RowData(cells); }
Example 5
Source File: CassandraConnectorTableService.java From metacat with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public List<TableInfo> list( @Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable ) { final String keyspace = name.getDatabaseName(); log.debug("Attempting to list tables in Cassandra keyspace {} for request {}", keyspace, context); try { final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new DatabaseNotFoundException(name); } // TODO: Should we include views? final List<TableInfo> tables = Lists.newArrayList(); for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) { if (prefix != null && !tableMetadata.getName().startsWith(prefix.getTableName())) { continue; } tables.add(this.getTableInfo(name, tableMetadata)); } // Sort if (sort != null) { final Comparator<TableInfo> tableComparator = Comparator.comparing((t) -> t.getName().getTableName()); ConnectorUtils.sort(tables, sort, tableComparator); } // Paging final List<TableInfo> pagedTables = ConnectorUtils.paginate(tables, pageable); log.debug( "Listed {} tables in Cassandra keyspace {} for request {}", pagedTables.size(), keyspace, context ); return pagedTables; } catch (final DriverException de) { log.error(de.getMessage(), de); throw this.getExceptionMapper().toConnectorException(de, name); } }
Example 6
Source File: CassandraConnectorTableService.java From metacat with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public List<QualifiedName> listNames( @Nonnull @NonNull final ConnectorRequestContext context, @Nonnull @NonNull final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable ) { final String catalog = name.getCatalogName(); final String keyspace = name.getDatabaseName(); log.debug("Attempting to list table names in Cassandra keyspace {} for request {}", keyspace, context); try { final KeyspaceMetadata keyspaceMetadata = this.getCluster().getMetadata().getKeyspace(keyspace); if (keyspaceMetadata == null) { throw new DatabaseNotFoundException(name); } // TODO: Should we include views? final List<QualifiedName> tableNames = Lists.newArrayList(); for (final TableMetadata tableMetadata : keyspaceMetadata.getTables()) { final String tableName = tableMetadata.getName(); if (prefix != null && !tableName.startsWith(prefix.getTableName())) { continue; } tableNames.add(QualifiedName.ofTable(catalog, keyspace, tableName)); } // Sort if (sort != null) { final Comparator<QualifiedName> tableNameComparator = Comparator.comparing(QualifiedName::getTableName); ConnectorUtils.sort(tableNames, sort, tableNameComparator); } // Paging final List<QualifiedName> paged = ConnectorUtils.paginate(tableNames, pageable); log.debug("Listed {} table names in Cassandra keyspace {} for request {}", paged.size(), keyspace, context); return paged; } catch (final DriverException de) { log.error(de.getMessage(), de); throw this.getExceptionMapper().toConnectorException(de, name); } }
Example 7
Source File: MetadataResultSets.java From cassandra-jdbc-wrapper with Apache License 2.0 | 4 votes |
public CassandraMetadataResultSet makeTables(CassandraStatement statement, String schemaPattern, String tableNamePattern) throws SQLException { // 1. TABLE_CAT String => table catalog (may be null) // 2. TABLE_SCHEM String => table schema (may be null) // 3. TABLE_NAME String => table name // 4. TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". // 5. REMARKS String => explanatory comment on the table // 6. TYPE_CAT String => the types catalog (may be null) // 7. TYPE_SCHEM String => the types schema (may be null) // 8. TYPE_NAME String => type name (may be null) // 9. SELF_REFERENCING_COL_NAME String => name of the designated "identifier" column of a typed table (may be null) // 10. REF_GENERATION String => specifies how values in SELF_REFERENCING_COL_NAME are created. Values are "SYSTEM", "USER", "DERIVED". (may be null) final ArrayList<MetadataRow> schemas = Lists.newArrayList(); List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces(); for(KeyspaceMetadata keyspace:keyspaces){ if ("%".equals(schemaPattern)) schemaPattern = null; if((schemaPattern==null?keyspace.getName():schemaPattern).equals(keyspace.getName())){ Collection<TableMetadata> tables = keyspace.getTables(); if ("%".equals(tableNamePattern)) tableNamePattern = null; for(TableMetadata table:tables){ if((tableNamePattern==null?table.getName():tableNamePattern).equals(table.getName())){ MetadataRow row = new MetadataRow().addEntry("TABLE_CAT", statement.connection.getCatalog()) .addEntry("TABLE_SCHEM", keyspace.getName()) .addEntry("TABLE_NAME", table.getName()) .addEntry("TABLE_TYPE", TABLE_CONSTANT) .addEntry("REMARKS", table.getOptions().getComment()) .addEntry("TYPE_CAT", null) .addEntry("TYPE_SCHEM", null) .addEntry("TYPE_NAME", null) .addEntry("SELF_REFERENCING_COL_NAME", null) .addEntry("REF_GENERATION", null); schemas.add(row); } } } } CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas)); return result; }
Example 8
Source File: MetadataResultSets.java From cassandra-jdbc-wrapper with Apache License 2.0 | 4 votes |
public CassandraMetadataResultSet makeIndexes(CassandraStatement statement, String schema, String tableName, boolean unique, boolean approximate) throws SQLException { final ArrayList<MetadataRow> schemas = Lists.newArrayList(); List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces(); for(KeyspaceMetadata keyspace:keyspaces){ if(schema.equals(keyspace.getName())){ Collection<TableMetadata> tables = keyspace.getTables(); for(TableMetadata table:tables){ if(tableName.equals(table.getName())){ for(IndexMetadata index:table.getIndexes()){ MetadataRow row = new MetadataRow().addEntry("TABLE_CAT", statement.connection.getCatalog()) .addEntry("TABLE_SCHEM", keyspace.getName()) .addEntry("TABLE_NAME", table.getName()) .addEntry("NON_UNIQUE", true+"") .addEntry("INDEX_QUALIFIER", statement.connection.getCatalog()) .addEntry("INDEX_NAME", index.getName()) .addEntry("TYPE", DatabaseMetaData.tableIndexHashed+"") .addEntry("ORDINAL_POSITION", 1+"") .addEntry("COLUMN_NAME", index.getTarget()) .addEntry("ASC_OR_DESC", null) .addEntry("CARDINALITY", -1+"") .addEntry("PAGES", -1+"") .addEntry("FILTER_CONDITION", null); schemas.add(row); } } } } } CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas)); return result; //1.TABLE_CAT String => table catalog (may be null) //2.TABLE_SCHEM String => table schema (may be null) //3.TABLE_NAME String => table name //4.NON_UNIQUE boolean => Can index values be non-unique. false when TYPE is tableIndexStatistic //5.INDEX_QUALIFIER String => index catalog (may be null); null when TYPE is tableIndexStatistic //6.INDEX_NAME String => index name; null when TYPE is tableIndexStatistic //7.TYPE short => index type: - tableIndexStatistic - this identifies table statistics that are returned in conjuction with a table's index descriptions //- tableIndexClustered - this is a clustered index //- tableIndexHashed - this is a hashed index //- tableIndexOther - this is some other style of index // //8.ORDINAL_POSITION short => column sequence number within index; zero when TYPE is tableIndexStatistic //9.COLUMN_NAME String => column name; null when TYPE is tableIndexStatistic //10.ASC_OR_DESC String => column sort sequence, "A" => ascending, "D" => descending, may be null if sort sequence is not supported; null when TYPE is tableIndexStatistic //11.CARDINALITY int => When TYPE is tableIndexStatistic, then this is the number of rows in the table; otherwise, it is the number of unique values in the index. //12.PAGES int => When TYPE is tableIndexStatisic then this is the number of pages used for the table, otherwise it is the number of pages used for the current index. //13.FILTER_CONDITION String => Filter condition, if any. (may be null) /* StringBuilder query = new StringBuilder("SELECT keyspace_name, columnfamily_name, column_name, component_index, index_name, index_options, index_type FROM system.schema_columns");*/ }
Example 9
Source File: MetadataResultSets.java From cassandra-jdbc-wrapper with Apache License 2.0 | 4 votes |
public CassandraMetadataResultSet makePrimaryKeys(CassandraStatement statement, String schema, String tableName) throws SQLException { final ArrayList<MetadataRow> schemas = Lists.newArrayList(); List<KeyspaceMetadata> keyspaces = statement.connection.getClusterMetadata().getKeyspaces(); for(KeyspaceMetadata keyspace:keyspaces){ if(schema.equals(keyspace.getName())){ Collection<TableMetadata> tables = keyspace.getTables(); for(TableMetadata table:tables){ if(tableName.equals(table.getName())){ int seq=0; for(ColumnMetadata col:table.getPrimaryKey()){ MetadataRow row = new MetadataRow().addEntry("TABLE_CAT", statement.connection.getCatalog()) .addEntry("TABLE_SCHEM", keyspace.getName()) .addEntry("TABLE_NAME", table.getName()) .addEntry("COLUMN_NAME", col.getName()) .addEntry("KEY_SEQ", seq+"") .addEntry("PK_NAME", null); schemas.add(row); seq++; } } } } } CassandraMetadataResultSet result = new CassandraMetadataResultSet(statement,new MetadataResultSet().setRows(schemas)); return result; //1.TABLE_CAT String => table catalog (may be null) //2.TABLE_SCHEM String => table schema (may be null) //3.TABLE_NAME String => table name //4.COLUMN_NAME String => column name //5.KEY_SEQ short => sequence number within primary key( a value of 1 represents the first column of the primary key, a value of 2 would represent the second column within the primary key). //6.PK_NAME String => primary key name (may be null) }