com.datastax.driver.core.TableMetadata Java Examples

The following examples show how to use com.datastax.driver.core.TableMetadata. 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: CassandraConnectorTableService.java    From metacat with Apache License 2.0 6 votes vote down vote up
private TableInfo getTableInfo(
    @Nonnull @NonNull final QualifiedName name,
    @Nonnull @NonNull final TableMetadata tableMetadata
) {
    final ImmutableList.Builder<FieldInfo> fieldInfoBuilder = ImmutableList.builder();
    // TODO: Ignores clustering, primary key, index, etc columns. We need to rework TableInfo to support
    for (final ColumnMetadata column : tableMetadata.getColumns()) {
        final String dataType = column.getType().toString();
        fieldInfoBuilder.add(
            FieldInfo.builder()
                .name(column.getName())
                .sourceType(dataType)
                .type(this.typeConverter.toMetacatType(dataType))
                .build()
        );
    }
    return TableInfo.builder()
        .name(QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), tableMetadata.getName()))
        .fields(fieldInfoBuilder.build())
        .build();
}
 
Example #2
Source File: SchemaUpgrade.java    From glowroot with Apache License 2.0 6 votes vote down vote up
private void updateTwcsDtcsGcSeconds() throws Exception {
    logger.info("updating gc_grace_seconds on TWCS/DTCS tables...");
    for (TableMetadata table : session.getTables()) {
        String compactionClass = table.getOptions().getCompaction().get("class");
        if (compactionClass == null) {
            continue;
        }
        if (compactionClass
                .equals("org.apache.cassandra.db.compaction.TimeWindowCompactionStrategy")
                || compactionClass.equals(
                        "org.apache.cassandra.db.compaction.DateTieredCompactionStrategy")) {
            // see gc_grace_seconds related comments in Sessions.createTableWithTWCS()
            // for reasoning behind the value of 4 hours
            session.updateSchemaWithRetry("alter table " + table.getName()
                    + " with gc_grace_seconds = " + HOURS.toSeconds(4));
        }
    }
    logger.info("updating gc_grace_seconds on TWCS/DTCS tables - complete");
}
 
Example #3
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public void onTableAdded(TableMetadata tableMetadata) {
    log.debugf("Table added %s", tableMetadata.getName());
    long delay = Long.getLong("hawkular.metrics.cassandra.schema.refresh-delay", 5000);
    if(tableMetadata.getName().startsWith(TEMP_TABLE_NAME_PROTOTYPE)) {
        log.debugf("Registering prepared statements for table %s", tableMetadata.getName());
        Observable.fromCallable(() -> {
            prepareTempStatements(tableMetadata.getName(), tableToMapKey(tableMetadata.getName()));
            return null;
        })
                .subscribeOn(Schedulers.io())
                .retryWhen(errors -> errors.flatMap(error -> {
                    log.debugf("Failed to prepare statements for table %s. Retrying in %d ms",
                            tableMetadata.getName(), delay);
                    return Observable.timer(delay, TimeUnit.MILLISECONDS);
                }))
                .doOnCompleted(() -> log.debugf("Finished preparing statements for table %s",
                        tableMetadata.getName()))
                .subscribe();
    }
}
 
Example #4
Source File: ClusterManagerTest.java    From scalardb with Apache License 2.0 6 votes vote down vote up
@Test
public void getMetadata_ExistingKeyspaceAndTableGiven_ShouldReturnMetadata() {
  // Arrange
  manager.getSession();
  Metadata metadata = mock(Metadata.class);
  KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
  TableMetadata tableMetadata = mock(TableMetadata.class);
  when(cluster.getMetadata()).thenReturn(metadata);
  when(metadata.getKeyspace(anyString())).thenReturn(keyspaceMetadata);
  when(keyspaceMetadata.getTable(anyString())).thenReturn(tableMetadata);

  // Act
  TableMetadata actual = manager.getMetadata(ANY_KEYSPACE_NAME, ANY_TABLE_NAME);

  // Assert
  assertThat(actual).isEqualTo(tableMetadata);
}
 
Example #5
Source File: CassandraDeepJobConfig.java    From deep-spark with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the output column family if not exists. <br/>
 * We first check if the column family exists. <br/>
 * If not, we get the first element from <i>tupleRDD</i> and we use it as a template to get columns metadata.
 * <p>
 * This is a very heavy operation since to obtain the schema we need to get at least one element of the output RDD.
 * </p>
 *
 * @param first the pair RDD.
 */
public void createOutputTableIfNeeded(Tuple2<Cells, Cells> first) {

    TableMetadata metadata = getSession()
            .getCluster()
            .getMetadata()
            .getKeyspace(this.catalog)
            .getTable(quote(this.table));

    if (metadata == null && !createTableOnWrite) {
        throw new DeepIOException("Cannot write RDD, output table does not exists and configuration object has " +
                "'createTableOnWrite' = false");
    }

    if (metadata != null) {
        return;
    }

    if (first._1() == null || first._1().isEmpty()) {
        throw new DeepNoSuchFieldException("no key structure found on row metadata");
    }
    String createTableQuery = createTableQueryGenerator(first._1(), first._2(), this.catalog,
            quote(this.table));
    getSession().execute(createTableQuery);
    waitForNewTableMetadata();
}
 
Example #6
Source File: SchemaUpgradeIT.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private static void backup(String keyspace) throws Exception {
    String cqlsh =
            "cassandra/apache-cassandra-" + CassandraWrapper.CASSANDRA_VERSION + "/bin/cqlsh";
    if (System.getProperty("os.name").startsWith("Windows")) {
        cqlsh += ".bat";
    }
    String backupFolder = "src/test/resources/backup-0.9.1/";
    Cluster cluster = Clusters.newCluster();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    for (TableMetadata table : cluster.getMetadata().getKeyspace(keyspace).getTables()) {
        ProcessBuilder processBuilder = new ProcessBuilder(cqlsh, "-e",
                "copy " + keyspace + "." + table.getName() + " to '" + backupFolder
                        + table.getName() + ".csv' with NULL='NULL.NULL.NULL.NULL' and"
                        + " NUMPROCESSES = 1");
        processBuilder.redirectErrorStream(true);
        Process process = processBuilder.start();
        executor.submit(new ConsoleOutputPipe(process.getInputStream(), System.out));
        process.waitFor();
    }
    executor.shutdown();
    cluster.close();
}
 
Example #7
Source File: CassandraDeepJobConfig.java    From deep-spark with Apache License 2.0 6 votes vote down vote up
private void validateAdditionalFilters(TableMetadata tableMetadata) {
    for (Map.Entry<String, Serializable> entry : additionalFilters.entrySet()) {
        /* check if there's an index specified on the provided column */
        ColumnMetadata columnMetadata = tableMetadata.getColumn(entry.getKey());

        if (columnMetadata == null) {
            throw new DeepNoSuchFieldException("No column with name " + entry.getKey() + " has been found on " +
                    "table " + this.catalog + "." + this.table);
        }

        if (columnMetadata.getIndex() == null) {
            throw new DeepIndexNotFoundException("No index has been found on column " + columnMetadata.getName()
                    + " on table " + this.catalog + "." + this.table);
        }
    }
}
 
Example #8
Source File: SchemaUpgrade.java    From glowroot with Apache License 2.0 6 votes vote down vote up
private static @Nullable Integer getSchemaVersion(Session session) throws Exception {
    ResultSet results =
            session.read("select schema_version from schema_version where one = 1");
    Row row = results.one();
    if (row != null) {
        return row.getInt(0);
    }
    TableMetadata agentTable = session.getTable("agent");
    if (agentTable != null && agentTable.getColumn("system_info") != null) {
        // special case, this is glowroot version 0.9.1, the only version supporting upgrades
        // prior to schema_version table
        return 1;
    }
    // new installation
    return null;
}
 
Example #9
Source File: DatastaxCrudFactory.java    From SimpleFlatMapper with MIT License 6 votes vote down vote up
private static String insertQuery(TableMetadata tableMetadata, String... options) {
    Insert insert = QueryBuilder.insertInto(tableMetadata);

    if (options != null) {
        Insert.Options using = insert.using();
        for (String option : options) {
            if ("TTL".equals(option)) {
                using.and(QueryBuilder.ttl(QueryBuilder.bindMarker()));
            } else {
                using.and(QueryBuilder.timestamp(QueryBuilder.bindMarker()));
            }
        }
    }

    List<ColumnMetadata> columns = tableMetadata.getColumns();

    for(ColumnMetadata column : columns) {
        insert.value(column.getName(), QueryBuilder.bindMarker());
    }

    return insert.toString();
}
 
Example #10
Source File: DatastaxCrudFactory.java    From SimpleFlatMapper with MIT License 6 votes vote down vote up
private static <T, K> DatastaxCrud<T, K> createCrud(Type target, Type keyTarget,
                                                    TableMetadata tableMetadata,
                                                    Session session,
                                                    DatastaxMapperFactory mapperFactory) {
    DatastaxMapper<T> selectMapper = selectMapper(target, tableMetadata, mapperFactory);
    return new DatastaxCrud<T, K>(
            session.prepare(insertQuery(tableMetadata)),
            session.prepare(insertQuery(tableMetadata, "TTL", "TIMESTAMP")),
            session.prepare(insertQuery(tableMetadata, "TTL" )),
            session.prepare(insertQuery(tableMetadata, "TIMESTAMP")),
            session.prepare(readQuery(tableMetadata)),
            session.prepare(deleteQuery(tableMetadata)),
            session.prepare(deleteQueryWithTimestamp(tableMetadata)),
            DatastaxCrudFactory.<T>insertSetter(target, tableMetadata, mapperFactory, 0),
            DatastaxCrudFactory.<K>keySetter(keyTarget, tableMetadata, mapperFactory, 0),
            DatastaxCrudFactory.<K>keySetter(keyTarget, tableMetadata, mapperFactory, 1),
            selectMapper,
            tableMetadata.getColumns().size(), session);
}
 
Example #11
Source File: SnapshotProcessor.java    From debezium-incubator with Apache License 2.0 6 votes vote down vote up
/**
 * Build the SELECT query statement for execution. For every non-primary-key column, the TTL, WRITETIME, and execution
 * time are also queried.
 *
 * For example, a table t with columns a, b, and c, where A is the partition key, B is the clustering key, and C is a
 * regular column, looks like the following:
 * <pre>
 *     {@code SELECT now() as execution_time, a, b, c, TTL(c) as c_ttl, WRITETIME(c) as c_writetime FROM t;}
 * </pre>
 */
private static BuiltStatement generateSnapshotStatement(TableMetadata tableMetadata) {
    List<String> allCols = tableMetadata.getColumns().stream().map(ColumnMetadata::getName).collect(Collectors.toList());
    Set<String> primaryCols = tableMetadata.getPrimaryKey().stream().map(ColumnMetadata::getName).collect(Collectors.toSet());
    List<String> collectionCols = tableMetadata.getColumns().stream().filter(cm -> collectionTypes.contains(cm.getType().getName()))
            .map(ColumnMetadata::getName).collect(Collectors.toList());

    Select.Selection selection = QueryBuilder.select().raw(CASSANDRA_NOW_UNIXTIMESTAMP).as(EXECUTION_TIME_ALIAS);
    for (String col : allCols) {
        selection.column(withQuotes(col));

        if (!primaryCols.contains(col) && !collectionCols.contains(col)) {
            selection.ttl(withQuotes(col)).as(ttlAlias(col));
        }
    }
    return selection.from(tableMetadata.getKeyspace().getName(), tableMetadata.getName());
}
 
Example #12
Source File: CassandraDeepJobConfig.java    From deep-spark with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */

@Override
public synchronized Map<String, Cell> columnDefinitions() {
    if (columnDefinitionMap != null) {
        return columnDefinitionMap;
    }

    TableMetadata tableMetadata = fetchTableMetadata();

    if (tableMetadata == null && !createTableOnWrite) {
        LOG.warn("Configuration not suitable for writing RDD: output table does not exists and configuration " +
                "object has 'createTableOnWrite' = false");

        return null;
    } else if (tableMetadata == null) {
        return null;
    }

    initColumnDefinitionMap(tableMetadata);

    return columnDefinitionMap;
}
 
Example #13
Source File: CassandraUtils.java    From sstable-tools with Apache License 2.0 6 votes vote down vote up
public static Cluster loadTablesFromRemote(String host, int port, String cfidOverrides) throws IOException {
    Map<String, UUID> cfs = parseOverrides(cfidOverrides);
    Cluster.Builder builder = Cluster.builder().addContactPoints(host).withPort(port);
    Cluster cluster = builder.build();
    Metadata metadata = cluster.getMetadata();
    IPartitioner partitioner = FBUtilities.newPartitioner(metadata.getPartitioner());
    if (DatabaseDescriptor.getPartitioner() == null)
        DatabaseDescriptor.setPartitionerUnsafe(partitioner);
    for (com.datastax.driver.core.KeyspaceMetadata ksm : metadata.getKeyspaces()) {
        if (!ksm.getName().equals("system")) {
            for (TableMetadata tm : ksm.getTables()) {
                String name = ksm.getName()+"."+tm.getName();
                try {
                    CassandraUtils.tableFromCQL(
                            new ByteArrayInputStream(tm.asCQLQuery().getBytes()),
                            cfs.get(name) != null ? cfs.get(name) : tm.getId());
                } catch(SyntaxException e) {
                    // ignore tables that we cant parse (probably dse)
                    logger.debug("Ignoring table " + name + " due to syntax exception " + e.getMessage());
                }
            }
        }
    }
    return cluster;
}
 
Example #14
Source File: CassandraIntervalCollectionPersistor.java    From brein-time-utilities with Apache License 2.0 6 votes vote down vote up
protected void createColumnFamily() {
    final String ks = getKeySpace();
    final String cf = getColumnFamily();

    final KeyspaceMetadata keySpaceMeta = this.cluster.getMetadata().getKeyspace(ks);
    final TableMetadata tableMetadata = keySpaceMeta.getTable(cf);

    // check if the table exists
    if (tableMetadata != null) {
        return;
    }

    final String stmt = String.format("CREATE TABLE %s (\n" +
            "  " + KEY_COLUMN + " text,\n" +
            "  " + COLL_COLUMN + " blob,\n" +
            "  PRIMARY KEY (" + KEY_COLUMN + ")\n" +
            ");", cf);

    getSession().execute(stmt);
}
 
Example #15
Source File: SchemaUpgrade.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private void updateStcsUncheckedTombstoneCompaction() throws Exception {
    for (TableMetadata table : session.getTables()) {
        String compactionClass = table.getOptions().getCompaction().get("class");
        if (compactionClass != null && compactionClass
                .equals("org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy")) {
            session.updateSchemaWithRetry("alter table " + table.getName()
                    + " with compaction = { 'class' : 'SizeTieredCompactionStrategy',"
                    + " 'unchecked_tombstone_compaction' : true }");
        }
    }
}
 
Example #16
Source File: DatastaxCrudFactory.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
private static <K> BoundStatementMapper<K> keySetter(Type keyTarget, TableMetadata tableMetadata, DatastaxMapperFactory mapperFactory, int offset) {
    SettableDataMapperBuilder<K> mapperBuilder = mapperFactory.newBuilderFrom(keyTarget);
    int i = offset;
    for(ColumnMetadata columnMetadata : tableMetadata.getPrimaryKey()) {
        mapperBuilder.addColumn(DatastaxColumnKey.of(columnMetadata, i++));
    }
    return new BoundStatementMapper<K>(mapperBuilder.mapper());
}
 
Example #17
Source File: CassandraSession.java    From presto with Apache License 2.0 5 votes vote down vote up
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 #18
Source File: DatastaxCrudFactory.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
private static <T> BoundStatementMapper<T> insertSetter(Type target, TableMetadata tableMetadata, DatastaxMapperFactory mapperFactory, int offset) {
    SettableDataMapperBuilder<T> mapperBuilder = mapperFactory.newBuilderFrom(target);
    int i = offset;
    for(ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
        mapperBuilder.addColumn(DatastaxColumnKey.of(columnMetadata, i++));
    }
    return new BoundStatementMapper<T>(mapperBuilder.mapper());
}
 
Example #19
Source File: SchemaUpgrade.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private void updateLcsUncheckedTombstoneCompaction() throws Exception {
    for (TableMetadata table : session.getTables()) {
        String compactionClass = table.getOptions().getCompaction().get("class");
        if (compactionClass != null && compactionClass
                .equals("org.apache.cassandra.db.compaction.LeveledCompactionStrategy")) {
            session.updateSchemaWithRetry("alter table " + table.getName()
                    + " with compaction = { 'class' : 'LeveledCompactionStrategy',"
                    + " 'unchecked_tombstone_compaction' : true }");
        }
    }
}
 
Example #20
Source File: DatastaxCrudDSL.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
public DatastaxCrud<T, K> to(Session session, String keyspace,  String table) {
    TableMetadata tableMetadata =
            session.getCluster().getMetadata().getKeyspace(keyspace).getTable(table);

    return DatastaxCrudFactory.<T, K>newInstance(targetType,
            keyType,
            tableMetadata,
            session,
            datastaxMapperFactory);
}
 
Example #21
Source File: CassandraTableTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void initializeShouldExecuteReturnAlreadyDoneWhenTableExists() {
    KeyspaceMetadata keyspace = mock(KeyspaceMetadata.class);
    when(keyspace.getTable(NAME)).thenReturn(mock(TableMetadata.class));
    Session session = mock(Session.class);

    assertThat(TABLE.initialize(keyspace, session))
            .isEqualByComparingTo(ALREADY_DONE);

    verify(keyspace).getTable(NAME);
    verify(session, never()).execute(STATEMENT);
}
 
Example #22
Source File: CassandraUtils.java    From ingestion with Apache License 2.0 5 votes vote down vote up
public static TableMetadata getTableMetadata(final Session session, final String keyspace, final String table) {
  Preconditions.checkNotNull(session);
  Preconditions.checkNotNull(keyspace);
  Preconditions.checkNotNull(table);
  final KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
  if (keyspaceMetadata == null) {
    throw new IllegalStateException(String.format("Keyspace %s does not exist", keyspace));
  }
  final TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
  if (tableMetadata == null) {
    throw new IllegalStateException(String.format("Table %s.%s does not exist", keyspace, table));
  }
  return tableMetadata;
}
 
Example #23
Source File: AbstractUpsertOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
private void registerPrimaryKeyColumnDefinitions(final TableMetadata tableMetadata)
{
  List<ColumnMetadata> primaryKeyColumns = tableMetadata.getPrimaryKey();
  for (ColumnMetadata primaryColumn : primaryKeyColumns) {
    columnDefinitions.put(primaryColumn.getName(), primaryColumn.getType());
    pkColumnNames.add(primaryColumn.getName());
    parseForSpecialDataType(primaryColumn);
  }
}
 
Example #24
Source File: AbstractUpsertOutputOperator.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
private void registerNonPKColumnDefinitions(final TableMetadata tableMetadata)
{
  List<ColumnMetadata> colInfoForTable = tableMetadata.getColumns();
  for (ColumnMetadata aColumnDefinition : colInfoForTable) {
    if (aColumnDefinition.getType().isCollection()) {
      collectionColumns.add(aColumnDefinition.getName());
    }
    if (!pkColumnNames.contains(aColumnDefinition.getName())) {
      columnDefinitions.put(aColumnDefinition.getName(), aColumnDefinition.getType());
      regularColumns.add(aColumnDefinition.getName());
    }
    parseForSpecialDataType(aColumnDefinition);
  }
}
 
Example #25
Source File: TestCassandraUtils.java    From ingestion with Apache License 2.0 5 votes vote down vote up
@Test
public void getTableMetadata() {
  final Session session = mock(Session.class);
  final Cluster cluster = mock(Cluster.class);
  final Metadata metadata = mock(Metadata.class);
  final KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
  final TableMetadata tableMetadata = mock(TableMetadata.class);
  when(session.getCluster()).thenReturn(cluster);
  when(cluster.getMetadata()).thenReturn(metadata);
  when(metadata.getKeyspace("keyspace")).thenReturn(keyspaceMetadata);
  when(keyspaceMetadata.getTable("table")).thenReturn(tableMetadata);
  assertThat(CassandraUtils.getTableMetadata(session, "keyspace", "table")).isNotNull();
}
 
Example #26
Source File: CompressionTest.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonExistantCompression() throws Exception {
    // Write to past .. should go to data_0 table
    long start = now().minusDays(2).getMillis();
    createAndInsertMetrics(start, 100, 1);
    compressData(start); // Try to compress table in the past

    // Verify that the out of order table was not dropped
    TableMetadata table = session.getCluster().getMetadata().getKeyspace(getKeyspace())
            .getTable(DataAccessImpl.OUT_OF_ORDER_TABLE_NAME);

    assertNotNull(table, "data_0 should not have been dropped");

    TestSubscriber<Long> ts = new TestSubscriber<>();

    // Verify that the out of order table was not compressed
    rxSession.executeAndFetch(String.format("SELECT COUNT(*) FROM %s", DataAccessImpl.OUT_OF_ORDER_TABLE_NAME))
            .map(r -> r.getLong(0))
            .subscribe(ts);

    ts.awaitTerminalEvent(2, TimeUnit.SECONDS);
    ts.assertNoErrors();
    ts.assertCompleted();
    List<Long> onNextEvents = ts.getOnNextEvents();
    assertEquals(onNextEvents.size(), 1);
    assertEquals(onNextEvents.get(0).longValue(), 100);
}
 
Example #27
Source File: DeltaPlacement.java    From emodb with Apache License 2.0 5 votes vote down vote up
private BlockedDeltaTableDDL createBlockedDeltaTableDDL(String tableName) {
    TableMetadata tableMetadata = _keyspace.getKeyspaceMetadata().getTable(tableName);
    String rowKeyColumnName = tableMetadata.getPrimaryKey().get(0).getName();
    String timeSeriesColumnName = tableMetadata.getPrimaryKey().get(1).getName();
    String blockColumnName = tableMetadata.getPrimaryKey().get(2).getName();
    String valueColumnName = tableMetadata.getColumns().get(3).getName();

    return new BlockedDeltaTableDDL(tableMetadata, rowKeyColumnName, timeSeriesColumnName, valueColumnName, blockColumnName);
}
 
Example #28
Source File: DeltaPlacement.java    From emodb with Apache License 2.0 5 votes vote down vote up
private TableDDL creatHistoryTableDDL(String tableName) {
    TableMetadata tableMetadata = _keyspace.getKeyspaceMetadata().getTable(tableName);
    String rowKeyColumnName = tableMetadata.getPrimaryKey().get(0).getName();
    String timeSeriesColumnName = tableMetadata.getPrimaryKey().get(1).getName();
    String valueColumnName = tableMetadata.getColumns().get(2).getName();

    return new TableDDL(tableMetadata, rowKeyColumnName, timeSeriesColumnName, valueColumnName);
}
 
Example #29
Source File: CassandraDeepJobConfig.java    From deep-spark with Apache License 2.0 5 votes vote down vote up
/**
 * Fetches table metadata from the underlying datastore, using DataStax java driver.
 *
 * @return the table metadata as returned by the driver.
 */
public TableMetadata fetchTableMetadata() {

    Metadata metadata = getSession().getCluster().getMetadata();
    KeyspaceMetadata ksMetadata = metadata.getKeyspace(quote(this.catalog));

    if (ksMetadata != null) {
        return ksMetadata.getTable(quote(this.table));
    } else {
        return null;
    }
}
 
Example #30
Source File: DatastaxCrudFactory.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
public static <T, K> DatastaxCrud<T, K> newInstance(
        Type target,
        Type keyTarget,
        TableMetadata tableMetadata, Session session,
        DatastaxMapperFactory datastaxMapperFactory) {
    DatastaxMapperFactory mapperFactory = DatastaxMapperFactory.newInstance(datastaxMapperFactory);
    return createCrud(target, keyTarget, tableMetadata, session, mapperFactory);

}