use of com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseViewMetadata in project java-driver by datastax.
the class DseViewParser method parseView.
public DseViewMetadata parseView(AdminRow viewRow, CqlIdentifier keyspaceId, Map<CqlIdentifier, UserDefinedType> userTypes) {
// Cassandra 3.0 (no views in earlier versions):
// CREATE TABLE system_schema.views (
// keyspace_name text,
// view_name text,
// base_table_id uuid,
// base_table_name text,
// bloom_filter_fp_chance double,
// caching frozen<map<text, text>>,
// cdc boolean,
// comment text,
// compaction frozen<map<text, text>>,
// compression frozen<map<text, text>>,
// crc_check_chance double,
// dclocal_read_repair_chance double,
// default_time_to_live int,
// extensions frozen<map<text, blob>>,
// gc_grace_seconds int,
// id uuid,
// include_all_columns boolean,
// max_index_interval int,
// memtable_flush_period_in_ms int,
// min_index_interval int,
// read_repair_chance double,
// speculative_retry text,
// where_clause text,
// PRIMARY KEY (keyspace_name, view_name)
// ) WITH CLUSTERING ORDER BY (view_name ASC)
CqlIdentifier viewId = CqlIdentifier.fromInternal(viewRow.getString("view_name"));
UUID uuid = viewRow.getUuid("id");
CqlIdentifier baseTableId = CqlIdentifier.fromInternal(viewRow.getString("base_table_name"));
boolean includesAllColumns = MoreObjects.firstNonNull(viewRow.getBoolean("include_all_columns"), false);
String whereClause = viewRow.getString("where_clause");
List<RawColumn> rawColumns = RawColumn.toRawColumns(rows.columns().getOrDefault(keyspaceId, ImmutableMultimap.of()).get(viewId));
if (rawColumns.isEmpty()) {
LOG.warn("[{}] Processing VIEW refresh for {}.{} but found no matching rows, skipping", logPrefix, keyspaceId, viewId);
return null;
}
Collections.sort(rawColumns);
ImmutableMap.Builder<CqlIdentifier, ColumnMetadata> allColumnsBuilder = ImmutableMap.builder();
ImmutableList.Builder<ColumnMetadata> partitionKeyBuilder = ImmutableList.builder();
ImmutableMap.Builder<ColumnMetadata, ClusteringOrder> clusteringColumnsBuilder = ImmutableMap.builder();
for (RawColumn raw : rawColumns) {
DataType dataType = rows.dataTypeParser().parse(keyspaceId, raw.dataType, userTypes, context);
DseColumnMetadata column = new DefaultDseColumnMetadata(keyspaceId, viewId, raw.name, dataType, raw.kind.equals(RawColumn.KIND_STATIC));
switch(raw.kind) {
case RawColumn.KIND_PARTITION_KEY:
partitionKeyBuilder.add(column);
break;
case RawColumn.KIND_CLUSTERING_COLUMN:
clusteringColumnsBuilder.put(column, raw.reversed ? ClusteringOrder.DESC : ClusteringOrder.ASC);
break;
default:
}
allColumnsBuilder.put(column.getName(), column);
}
Map<CqlIdentifier, Object> options;
try {
options = parseOptions(viewRow);
} catch (Exception e) {
// Options change the most often, so be especially lenient if anything goes wrong.
Loggers.warnWithException(LOG, "[{}] Error while parsing options for {}.{}, getOptions() will be empty", logPrefix, keyspaceId, viewId, e);
options = Collections.emptyMap();
}
return new DefaultDseViewMetadata(keyspaceId, viewId, baseTableId, includesAllColumns, whereClause, uuid, partitionKeyBuilder.build(), clusteringColumnsBuilder.build(), allColumnsBuilder.build(), options);
}
Aggregations