com.datastax.driver.core.ColumnMetadata Java Examples

The following examples show how to use com.datastax.driver.core.ColumnMetadata. 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: CellData.java    From debezium-incubator with Apache License 2.0 6 votes vote down vote up
static Schema cellSchema(ColumnMetadata cm, boolean optional) {
    AbstractType<?> convertedType = CassandraTypeConverter.convert(cm.getType());
    Schema valueSchema = CassandraTypeDeserializer.getSchemaBuilder(convertedType).optional().build();
    if (valueSchema != null) {
        SchemaBuilder schemaBuilder = SchemaBuilder.struct().name(cm.getName())
                .field(CELL_VALUE_KEY, valueSchema)
                .field(CELL_DELETION_TS_KEY, Schema.OPTIONAL_INT64_SCHEMA)
                .field(CELL_SET_KEY, Schema.BOOLEAN_SCHEMA);
        if (optional) {
            schemaBuilder.optional();
        }
        return schemaBuilder.build();
    }
    else {
        return null;
    }
}
 
Example #2
Source File: CqlCount.java    From cassandra-count with Apache License 2.0 6 votes vote down vote up
private PreparedStatement prepareStatement() {
List<ColumnMetadata> partkeys = cluster.getMetadata().getKeyspace(keyspaceName).getTable(tableName).getPartitionKey();
StringBuilder sb = new StringBuilder();
sb.append("SELECT COUNT(*) FROM ");
sb.append(keyspaceName).append(".").append(tableName);
sb.append(" WHERE Token(");
sb.append(partkeys.get(0).getName());
for (int i = 1; i < partkeys.size(); i++)
    sb.append(", ").append(partkeys.get(i).getName());
sb.append(") > ? AND Token(");
sb.append(partkeys.get(0).getName());
for (int i = 1; i < partkeys.size(); i++)
    sb.append(",").append(partkeys.get(i).getName());
sb.append(") <= ?");

debugPrint("Query: " + sb.toString(), true, 2);

return session.prepare(sb.toString()).setConsistencyLevel(consistencyLevel);
   }
 
Example #3
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 #4
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 #5
Source File: SnapshotProcessor.java    From debezium-incubator with Apache License 2.0 6 votes vote down vote up
/**
 * This function extracts the relevant row data from {@link Row} and updates the maximum writetime for each row.
 */
private static RowData extractRowData(Row row, List<ColumnMetadata> columns, Set<String> partitionKeyNames, Set<String> clusteringKeyNames, Object executionTime) {
    RowData rowData = new RowData();

    for (ColumnMetadata columnMetadata : columns) {
        String name = columnMetadata.getName();
        Object value = readCol(row, name, columnMetadata);
        Object deletionTs = null;
        CellData.ColumnType type = getType(name, partitionKeyNames, clusteringKeyNames);

        if (type == CellData.ColumnType.REGULAR && value != null && !collectionTypes.contains(columnMetadata.getType().getName())) {
            Object ttl = readColTtl(row, name);
            if (ttl != null && executionTime != null) {
                deletionTs = calculateDeletionTs(executionTime, ttl);
            }
        }

        CellData cellData = new CellData(name, value, deletionTs, type);
        rowData.addCell(cellData);
    }

    return rowData;
}
 
Example #6
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 #7
Source File: AbstractUpsertOutputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
private void parseForSpecialDataType(final ColumnMetadata aColumnDefinition)
{
  switch (aColumnDefinition.getType().getName()) {
    case COUNTER:
      counterColumns.add(aColumnDefinition.getName());
      break;
    case MAP:
      mapColumns.add(aColumnDefinition.getName());
      break;
    case SET:
      setColumns.add(aColumnDefinition.getName());
      break;
    case LIST:
      listColumns.add(aColumnDefinition.getName());
      break;
    case UDT:
      userDefinedTypeColumns.add(aColumnDefinition.getName());
      break;
    default:
      break;
  }
}
 
Example #8
Source File: TableMetadata.java    From scalardb with Apache License 2.0 6 votes vote down vote up
public TableMetadata(com.datastax.driver.core.TableMetadata tableMetadata) {
  this.partitionKeyNames =
      ImmutableSet.copyOf(
          tableMetadata
              .getPartitionKey()
              .stream()
              .map(ColumnMetadata::getName)
              .collect(Collectors.toSet()));
  this.clusteringColumnNames =
      ImmutableSet.copyOf(
          tableMetadata
              .getClusteringColumns()
              .stream()
              .map(ColumnMetadata::getName)
              .collect(Collectors.toSet()));
}
 
Example #9
Source File: CassandraTable.java    From ingestion with Apache License 2.0 6 votes vote down vote up
public CassandraTable(
    final Session session,
    final TableMetadata table,
    final ConsistencyLevel consistencyLevel,
    final String bodyColumn,
    final boolean ignoreCase) {
  this.session = session;
  this.table = table;
  this.consistencyLevel = consistencyLevel;
  this.bodyColumn = bodyColumn;

  this.columns = table.getColumns();
  this.totalColumns = this.columns.size();
  this.primaryKeys = new ArrayList<String>();
  for (final ColumnMetadata column : table.getPrimaryKey()) {
    primaryKeys.add(column.getName());
  }

  this.ignoreCase = ignoreCase;
}
 
Example #10
Source File: CassandraTable.java    From ingestion with Apache License 2.0 6 votes vote down vote up
public Map<String, Object> parse(final Event event) {
  // translate to lowercase for ignorecase option
  final Map<String, String> headers = ignoreCase ? processHeadersIgnoreCase(event.getHeaders())
      : event.getHeaders();
  final int maxValues = Math.min(headers.size(), totalColumns);
  final Map<String, Object> result = new HashMap<String, Object>(maxValues);

  for (final ColumnMetadata column : columns) {
    final String columnName = ignoreCase ? column.getName().toLowerCase() : column.getName();

    if (headers.containsKey(columnName) && !columnName.equals(bodyColumn)) {
      result.put(columnName, parseValue(column.getType(), headers.get(columnName)));
    } else if (columnName.equals(bodyColumn)) {
      result.put(columnName, parseValue(column.getType(), new String(event.getBody(), Charsets.UTF_8)));
    }
  }

  return result;
}
 
Example #11
Source File: TestCassandraTable.java    From ingestion with Apache License 2.0 6 votes vote down vote up
private void mockTableMetadata() {
  final ColumnMetadata idColumn = mock(ColumnMetadata.class);
  when(idColumn.getName()).thenReturn("id");
  when(idColumn.getType()).thenReturn(DataType.cint());

  final ColumnMetadata textColumn = mock(ColumnMetadata.class);
  when(textColumn.getName()).thenReturn("text_col");
  when(textColumn.getType()).thenReturn(DataType.text());

  final KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
  when(keyspaceMetadata.getName()).thenReturn("my_keyspace");

  when(tableMetadata.getName()).thenReturn("my_table");
  when(tableMetadata.getColumns()).thenReturn(ImmutableList.of(idColumn, textColumn));
  when(tableMetadata.getKeyspace()).thenReturn(keyspaceMetadata);
  when(tableMetadata.getPrimaryKey()).thenReturn(ImmutableList.of(idColumn));
}
 
Example #12
Source File: CassandraDataHandler.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private Map<String, Map<String, DataColumn>> generateMetaData() {
    Map<String, Map<String, DataColumn>> metadata = new HashMap<>();
    for (String tableName : this.tableList) {
        Map<String, DataColumn> dataColumnMap = new HashMap<>();
        for (ColumnMetadata columnMetadata : this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
                                                         .getTable(tableName).getColumns()) {
            DataColumn dataColumn;
            if (this.primaryKeys.get(tableName).contains(columnMetadata.getName())) {
                dataColumn = new DataColumn(columnMetadata.getName(),
                                            getDataType(columnMetadata.getType().getName()), false);
            } else {
                dataColumn = new DataColumn(columnMetadata.getName(),
                                            getDataType(columnMetadata.getType().getName()), true);
            }
            dataColumnMap.put(dataColumn.getColumnName(), dataColumn);
        }
        metadata.put(tableName, dataColumnMap);
    }
    return metadata;
}
 
Example #13
Source File: CassandraDataHandler.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private boolean deleteEntityTableNonTransactional(String tableName, ODataEntry entity) throws ODataServiceFault {
    List<ColumnMetadata> cassandraTableMetaData = this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
                                                              .getTable(tableName).getColumns();
    List<String> pKeys = this.primaryKeys.get(tableName);
    String query = createDeleteCQL(tableName);
    List<Object> values = new ArrayList<>();
    for (String column : pKeys) {
        if (entity.getNames().contains(column)) {
            bindParams(column, entity.getValue(column), values, cassandraTableMetaData);
        }
    }
    PreparedStatement statement = this.preparedStatementMap.get(query);
    if (statement == null) {
        statement = this.session.prepare(query);
        this.preparedStatementMap.put(query, statement);
    }
    ResultSet result = this.session.execute(statement.bind(values.toArray()));
    return result.wasApplied();
}
 
Example #14
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 #15
Source File: CqlRecordReader.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public RowIterator()
{
    AbstractType type = partitioner.getTokenValidator();
    ResultSet rs = session.execute(cqlQuery, type.compose(type.fromString(split.getStartToken())), type.compose(type.fromString(split.getEndToken())) );
    for (ColumnMetadata meta : cluster.getMetadata().getKeyspace(quote(keyspace)).getTable(quote(cfName)).getPartitionKey())
        partitionBoundColumns.put(meta.getName(), Boolean.TRUE);
    rows = rs.iterator();
}
 
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: 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 #18
Source File: DatastaxCrudFactory.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
private static <T> DatastaxMapper<T> selectMapper(Type target, TableMetadata tableMetadata, DatastaxMapperFactory mapperFactory) {
    DatastaxMapperBuilder<T> mapperBuilder = mapperFactory.newBuilder(target);
    int i = 0;
    for(ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
        mapperBuilder.addMapping(DatastaxColumnKey.of(columnMetadata, i++));
    }
    return mapperBuilder.mapper();
}
 
Example #19
Source File: DeepRecordReader.java    From deep-spark with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the column name for the lucene indexes. Null if there is no lucene index.
 *
 * @return Lucene index; null, if doesn't exist.
 */
private String getLuceneIndex() {
    String indexName = "";

    TableMetadata tableMetadata = config.fetchTableMetadata();
    List<ColumnMetadata> columns = tableMetadata.getColumns();
    for (ColumnMetadata column : columns) {
        if (column.getIndex() != null) {
            if (column.getIndex().isCustomIndex()) {
                indexName = column.getName();
            }
        }
    }
    return indexName;
}
 
Example #20
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 #21
Source File: SaveToCassandraOperationsService.java    From Decision with Apache License 2.0 5 votes vote down vote up
public void refreshTablenames() {
    Collection<TableMetadata> tableMetadatas = session.getCluster().getMetadata()
            .getKeyspace(STREAMING.STREAMING_KEYSPACE_NAME).getTables();
    tablenames = new HashMap<>();
    for (TableMetadata tableMetadata : tableMetadatas) {
        Set<String> columns = new HashSet<>();
        for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
            columns.add(columnMetadata.getName());
        }
        tablenames.put(tableMetadata.getName(), columns.hashCode());
    }
}
 
Example #22
Source File: CQLMetadataCache.java    From Doradus with Apache License 2.0 5 votes vote down vote up
/**
 * Return true if column values for the given namespace/store name are binary.
 * 
 * @param namespace Namespace (Keyspace) name.
 * @param storeName Store (ColumnFamily) name.
 * @return          True if the given table's column values are binary.
 */
public boolean columnValueIsBinary(String namespace, String storeName) {
    Boolean cachedValue = getCachedValueIsBinary(namespace, storeName);
    if(cachedValue != null) return cachedValue.booleanValue();
    
    String cqlKeyspace = CQLService.storeToCQLName(namespace);
    String tableName = CQLService.storeToCQLName(storeName);
    KeyspaceMetadata ksMetadata = m_cluster.getMetadata().getKeyspace(cqlKeyspace);
    TableMetadata tableMetadata = ksMetadata.getTable(tableName);
    ColumnMetadata colMetadata = tableMetadata.getColumn("value");
    boolean isBinary = colMetadata.getType().equals(DataType.blob());
    
    putCachedValueIsBinary(namespace, storeName, isBinary);
    return isBinary;
}
 
Example #23
Source File: TestCassandraSink.java    From ingestion with Apache License 2.0 5 votes vote down vote up
private void mockTableMetadataWithIdAndNameColumns(TableMetadata tableMetadata) {
  ColumnMetadata colId = mock(ColumnMetadata.class);
  when(colId.getName()).thenReturn("id");
  when(colId.getType()).thenReturn(DataType.text());
  ColumnMetadata colName = mock(ColumnMetadata.class);
  when(colName.getName()).thenReturn("name");
  when(colName.getType()).thenReturn(DataType.text());

  List<ColumnMetadata> listOfColumns = ImmutableList.of(colId, colName);
  when(tableMetadata.getColumns()).thenReturn(listOfColumns);
}
 
Example #24
Source File: CassandraClusterInfo.java    From hdfs2cass with Apache License 2.0 5 votes vote down vote up
/**
 * Get all column names from table metadata. Used if
 * {@link com.spotify.hdfs2cass.cassandra.utils.CassandraParams} don't specify column names.
 */
public String[] getAllColumnNames() {
  List<String> colNames = Lists.newArrayList();
  for (ColumnMetadata col : columns) {
    colNames.add(col.getName());
  }
  return colNames.toArray(new String[colNames.size()]);
}
 
Example #25
Source File: CassandraDataHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Override
public ODataEntry insertEntityToTable(String tableName, ODataEntry entity) throws ODataServiceFault {
    List<ColumnMetadata> cassandraTableMetaData = this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
                                                              .getTable(tableName).getColumns();
    for (String pkey : this.primaryKeys.get(tableName)) {
        if (this.tableMetaData.get(tableName).get(pkey).getColumnType().equals(ODataDataType.GUID) &&
            entity.getValue(pkey) == null) {
            UUID uuid = UUID.randomUUID();
            entity.addValue(pkey, uuid.toString());
        }
    }
    String query = createInsertCQL(tableName, entity);
    List<Object> values = new ArrayList<>();
    for (DataColumn column : this.tableMetaData.get(tableName).values()) {
        String columnName = column.getColumnName();
        if (entity.getNames().contains(columnName) && entity.getValue(columnName) != null) {
            bindParams(columnName, entity.getValue(columnName), values, cassandraTableMetaData);
        }
    }
    PreparedStatement statement = this.preparedStatementMap.get(query);
    if (statement == null) {
        statement = this.session.prepare(query);
        this.preparedStatementMap.put(query, statement);
    }
    this.session.execute(statement.bind(values.toArray()));
    entity.addValue(ODataConstants.E_TAG, ODataUtils.generateETag(this.configID, tableName, entity));
    return entity;
}
 
Example #26
Source File: CassandraDataHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private Map<String, List<String>> generatePrimaryKeyList() {
    Map<String, List<String>> primaryKeyMap = new HashMap<>();
    for (String tableName : this.tableList) {
        List<String> primaryKey = new ArrayList<>();
        for (ColumnMetadata columnMetadata : this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
                                                         .getTable(tableName).getPrimaryKey()) {
            primaryKey.add(columnMetadata.getName());
        }
        primaryKeyMap.put(tableName, primaryKey);
    }
    return primaryKeyMap;
}
 
Example #27
Source File: CassandraTarget.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private List<String> checkColumnMappings() throws StageException {
  List<String> invalidColumnMappings = new ArrayList<>();

  columnMappings = new TreeMap<>();
  for (CassandraFieldMappingConfig column : conf.columnNames) {
    columnMappings.put(column.columnName, column.field);
  }

  final String[] tableNameParts = conf.qualifiedTableName.split("\\.");
  final String keyspace = tableNameParts[0];
  final String table = tableNameParts[1];

  try (Cluster validationCluster = getCluster()) {
    final KeyspaceMetadata keyspaceMetadata = validationCluster.getMetadata().getKeyspace(keyspace);
    final TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
    final List<String> columns = Lists.transform(
        tableMetadata.getColumns(),
        new Function<ColumnMetadata, String>() {
          @Nullable
          @Override
          public String apply(ColumnMetadata columnMetadata) {
            return columnMetadata.getName();
          }
        }
    );

    invalidColumnMappings.addAll(columnMappings.keySet()
        .stream()
        .filter(columnName -> !columns.contains(columnName))
        .collect(Collectors.toList())
    );
  }

  return invalidColumnMappings;
}
 
Example #28
Source File: CassandraDataHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Override
public List<ODataEntry> readTableWithKeys(String tableName, ODataEntry keys) throws ODataServiceFault {
    List<ColumnMetadata> cassandraTableMetaData = this.session.getCluster().getMetadata().getKeyspace(this.keyspace)
                                                              .getTable(tableName).getColumns();
    List<String> pKeys = this.primaryKeys.get(tableName);
    String query = createReadSqlWithKeys(tableName, keys);
    List<Object> values = new ArrayList<>();
    for (String column : this.tableMetaData.get(tableName).keySet()) {
        if (keys.getNames().contains(column) && pKeys.contains(column)) {
            bindParams(column, keys.getValue(column), values, cassandraTableMetaData);
        }
    }
    PreparedStatement statement = this.preparedStatementMap.get(query);
    if (statement == null) {
        statement = this.session.prepare(query);
        this.preparedStatementMap.put(query, statement);
    }
    ResultSet resultSet = this.session.execute(statement.bind(values.toArray()));
    List<ODataEntry> entryList = new ArrayList<>();
    Iterator<Row> iterator = resultSet.iterator();
    ColumnDefinitions definitions = resultSet.getColumnDefinitions();
    while (iterator.hasNext()) {
        ODataEntry dataEntry = createDataEntryFromRow(tableName, iterator.next(), definitions);
        entryList.add(dataEntry);
    }
    return entryList;
}
 
Example #29
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 #30
Source File: CassandraUtils.java    From titus-control-plane with Apache License 2.0 5 votes vote down vote up
public static Pair<String, String> resolveColumnNamesInTwoColumnTable(Session sourceSession, String table) {
    TableMetadata tableMetadata = sourceSession.getCluster().getMetadata()
            .getKeyspace(sourceSession.getLoggedKeyspace())
            .getTable(table);
    String primaryKey = tableMetadata.getPartitionKey().get(0).getName();
    List<String> valueColumns = tableMetadata.getColumns().stream()
            .map(ColumnMetadata::getName)
            .filter(c -> !c.equals(primaryKey))
            .collect(Collectors.toList());
    Preconditions.checkState(valueColumns.size() == 1, "Expected one non primary key column, and is: %s", valueColumns);
    String valueColumn = valueColumns.get(0);

    return Pair.of(primaryKey, valueColumn);
}