use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.
the class PartitionImplementationTest method makeRow.
Row makeRow(Clustering clustering, String colValue) {
ColumnMetadata defCol = metadata.getColumn(new ColumnIdentifier("col", true));
Row.Builder row = BTreeRow.unsortedBuilder(TIMESTAMP);
row.newRow(clustering);
row.addCell(BufferCell.live(defCol, TIMESTAMP, ByteBufferUtil.bytes(colValue)));
return row.build();
}
use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.
the class SchemaLoader method compositeMultipleIndexCFMD.
public static TableMetadata.Builder compositeMultipleIndexCFMD(String ksName, String cfName) throws ConfigurationException {
TableMetadata.Builder builder = TableMetadata.builder(ksName, cfName).addPartitionKeyColumn("key", AsciiType.instance).addClusteringColumn("c1", AsciiType.instance).addRegularColumn("birthdate", LongType.instance).addRegularColumn("notbirthdate", LongType.instance).compression(getCompressionParameters());
Indexes.Builder indexes = Indexes.builder();
indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("birthdate", true), IndexTarget.Type.VALUES)), "birthdate_key_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
indexes.add(IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("notbirthdate", true), IndexTarget.Type.VALUES)), "notbirthdate_key_index", IndexMetadata.Kind.COMPOSITES, Collections.EMPTY_MAP));
return builder.indexes(indexes.build());
}
use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.
the class SchemaLoader method keysIndexCFMD.
public static TableMetadata.Builder keysIndexCFMD(String ksName, String cfName, boolean withIndex) {
TableMetadata.Builder builder = TableMetadata.builder(ksName, cfName).addPartitionKeyColumn("key", AsciiType.instance).addClusteringColumn("c1", AsciiType.instance).addStaticColumn("birthdate", LongType.instance).addStaticColumn("notbirthdate", LongType.instance).addRegularColumn("value", LongType.instance).compression(getCompressionParameters());
if (withIndex) {
IndexMetadata index = IndexMetadata.fromIndexTargets(Collections.singletonList(new IndexTarget(new ColumnIdentifier("birthdate", true), IndexTarget.Type.VALUES)), cfName + "_birthdate_composite_index", IndexMetadata.Kind.KEYS, Collections.EMPTY_MAP);
builder.indexes(Indexes.builder().add(index).build());
}
return builder;
}
use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.
the class CreateIndexStatement method apply.
public Keyspaces apply(Keyspaces schema) {
attrs.validate();
if (attrs.isCustom && attrs.customClass.equals(SASIIndex.class.getName()) && !DatabaseDescriptor.getSASIIndexesEnabled())
throw new InvalidRequestException("SASI indexes are disabled. Enable in cassandra.yaml to use.");
KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);
if (null == keyspace)
throw ire("Keyspace '%s' doesn't exist", keyspaceName);
TableMetadata table = keyspace.getTableOrViewNullable(tableName);
if (null == table)
throw ire("Table '%s' doesn't exist", tableName);
if (null != indexName && keyspace.hasIndex(indexName)) {
if (ifNotExists)
return schema;
throw ire("Index '%s' already exists", indexName);
}
if (table.isCounter())
throw ire("Secondary indexes on counter tables aren't supported");
if (table.isView())
throw ire("Secondary indexes on materialized views aren't supported");
if (Keyspace.open(table.keyspace).getReplicationStrategy().hasTransientReplicas())
throw new InvalidRequestException("Secondary indexes are not supported on transiently replicated keyspaces");
// guardrails to limit number of secondary indexes per table.
Guardrails.secondaryIndexesPerTable.guard(table.indexes.size() + 1, Strings.isNullOrEmpty(indexName) ? String.format("on table %s", table.name) : String.format("%s on table %s", indexName, table.name), state);
List<IndexTarget> indexTargets = Lists.newArrayList(transform(rawIndexTargets, t -> t.prepare(table)));
if (indexTargets.isEmpty() && !attrs.isCustom)
throw ire("Only CUSTOM indexes can be created without specifying a target column");
if (indexTargets.size() > 1) {
if (!attrs.isCustom)
throw ire("Only CUSTOM indexes support multiple columns");
Set<ColumnIdentifier> columns = new HashSet<>();
for (IndexTarget target : indexTargets) if (!columns.add(target.column))
throw ire("Duplicate column '%s' in index target list", target.column);
}
indexTargets.forEach(t -> validateIndexTarget(table, t));
String name = null == indexName ? generateIndexName(keyspace, indexTargets) : indexName;
IndexMetadata.Kind kind = attrs.isCustom ? IndexMetadata.Kind.CUSTOM : IndexMetadata.Kind.COMPOSITES;
Map<String, String> options = attrs.isCustom ? attrs.getOptions() : Collections.emptyMap();
IndexMetadata index = IndexMetadata.fromIndexTargets(indexTargets, name, kind, options);
// check to disallow creation of an index which duplicates an existing one in all but name
IndexMetadata equalIndex = tryFind(table.indexes, i -> i.equalsWithoutName(index)).orNull();
if (null != equalIndex) {
if (ifNotExists)
return schema;
throw ire("Index %s is a duplicate of existing index %s", index.name, equalIndex.name);
}
TableMetadata newTable = table.withSwapped(table.indexes.with(index));
newTable.validate();
return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.tables.withSwapped(newTable)));
}
use of org.hypertrace.entity.query.service.v1.ColumnIdentifier in project cassandra by apache.
the class RowTest method testResolve.
@Test
public void testResolve() {
ColumnMetadata defA = metadata.getColumn(new ColumnIdentifier("a", true));
ColumnMetadata defB = metadata.getColumn(new ColumnIdentifier("b", true));
Row.Builder builder = BTreeRow.unsortedBuilder();
builder.newRow(metadata.comparator.make("c1"));
writeSimpleCellValue(builder, defA, "a1", 0);
writeSimpleCellValue(builder, defA, "a2", 1);
writeSimpleCellValue(builder, defB, "b1", 1);
Row row = builder.build();
PartitionUpdate update = PartitionUpdate.singleRowUpdate(metadata, dk, row);
Unfiltered unfiltered = update.unfilteredIterator().next();
assertTrue(unfiltered.kind() == Unfiltered.Kind.ROW);
row = (Row) unfiltered;
assertEquals("a2", defA.cellValueType().getString(row.getCell(defA).buffer()));
assertEquals("b1", defB.cellValueType().getString(row.getCell(defB).buffer()));
assertEquals(2, row.columns().size());
}
Aggregations