com.datastax.driver.core.AbstractTableMetadata Java Examples

The following examples show how to use com.datastax.driver.core.AbstractTableMetadata. 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 6 votes vote down vote up
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));
    }
    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));
}
 
Example #2
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<ResultSet> createTempTablesIfNotExists(final Set<Long> timestamps) {
    return Observable.fromCallable(() -> {
        Set<String> tables = timestamps.stream()
                .map(this::getTempTableName)
                .collect(Collectors.toSet());

        // TODO This is an IO operation..
        metadata.getKeyspace(session.getLoggedKeyspace()).getTables().stream()
                .map(AbstractTableMetadata::getName)
                .filter(t -> t.startsWith(TEMP_TABLE_NAME_PROTOTYPE))
                .forEach(tables::remove);

        return tables;
    })

            .flatMapIterable(s -> s)
            .zipWith(Observable.interval(300, TimeUnit.MILLISECONDS), (st, l) -> st)
            .concatMap(this::createTemporaryTable);
}
 
Example #3
Source File: CassandraSession.java    From presto with Apache License 2.0 5 votes vote down vote up
private Optional<CassandraColumnHandle> buildColumnHandle(AbstractTableMetadata tableMetadata, ColumnMetadata columnMeta, boolean partitionKey, boolean clusteringKey, int ordinalPosition, boolean hidden)
{
    Optional<CassandraType> cassandraType = toCassandraType(columnMeta.getType().getName());
    if (cassandraType.isEmpty()) {
        log.debug("Unsupported column type: %s", columnMeta.getType().getName());
        return Optional.empty();
    }

    List<DataType> typeArgs = columnMeta.getType().getTypeArguments();
    for (DataType typeArgument : typeArgs) {
        if (!isFullySupported(typeArgument)) {
            log.debug("%s column has unsupported type: %s", columnMeta.getName(), typeArgument);
            return Optional.empty();
        }
    }
    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 Optional.of(new CassandraColumnHandle(columnMeta.getName(), ordinalPosition, cassandraType.get(), partitionKey, clusteringKey, indexed, hidden));
}
 
Example #4
Source File: CassandraSchema.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Get the collation of all clustering key columns.
 *
 * @return A RelCollations representing the collation of all clustering keys
 */
public List<RelFieldCollation> getClusteringOrder(String columnFamily, boolean view) {
  AbstractTableMetadata table;
  if (view) {
    table = getKeyspace().getMaterializedView("\"" + columnFamily + "\"");
  } else {
    table = getKeyspace().getTable("\"" + columnFamily + "\"");
  }

  List<ClusteringOrder> clusteringOrder = table.getClusteringOrder();
  List<RelFieldCollation> keyCollations = new ArrayList<>();

  int i = 0;
  for (ClusteringOrder order : clusteringOrder) {
    RelFieldCollation.Direction direction;
    switch (order) {
    case DESC:
      direction = RelFieldCollation.Direction.DESCENDING;
      break;
    case ASC:
    default:
      direction = RelFieldCollation.Direction.ASCENDING;
      break;
    }
    keyCollations.add(new RelFieldCollation(i, direction));
    i++;
  }

  return keyCollations;
}