use of org.apache.cassandra.cql3.statements.schema.IndexTarget.Type in project cassandra by apache.
the class DropAggregateStatement method announceMigration.
public Event.SchemaChange announceMigration(QueryState queryState, boolean isLocalOnly) throws RequestValidationException {
Collection<Function> olds = Schema.instance.getFunctions(functionName);
if (!argsPresent && olds != null && olds.size() > 1)
throw new InvalidRequestException(String.format("'DROP AGGREGATE %s' matches multiple function definitions; " + "specify the argument types by issuing a statement like " + "'DROP AGGREGATE %s (type, type, ...)'. Hint: use cqlsh " + "'DESCRIBE AGGREGATE %s' command to find all overloads", functionName, functionName, functionName));
Function old = null;
if (argsPresent) {
if (Schema.instance.getKeyspaceMetadata(functionName.keyspace) != null) {
List<AbstractType<?>> argTypes = new ArrayList<>(argRawTypes.size());
for (CQL3Type.Raw rawType : argRawTypes) argTypes.add(prepareType("arguments", rawType));
old = Schema.instance.findFunction(functionName, argTypes).orElse(null);
}
if (old == null || !(old instanceof AggregateFunction)) {
if (ifExists)
return null;
// just build a nicer error message
StringBuilder sb = new StringBuilder();
for (CQL3Type.Raw rawType : argRawTypes) {
if (sb.length() > 0)
sb.append(", ");
sb.append(rawType);
}
throw new InvalidRequestException(String.format("Cannot drop non existing aggregate '%s(%s)'", functionName, sb));
}
} else {
if (olds == null || olds.isEmpty() || !(olds.iterator().next() instanceof AggregateFunction)) {
if (ifExists)
return null;
throw new InvalidRequestException(String.format("Cannot drop non existing aggregate '%s'", functionName));
}
old = olds.iterator().next();
}
if (old.isNative())
throw new InvalidRequestException(String.format("Cannot drop aggregate '%s' because it is a " + "native (built-in) function", functionName));
MigrationManager.announceAggregateDrop((UDAggregate) old, isLocalOnly);
return new Event.SchemaChange(Event.SchemaChange.Change.DROPPED, Event.SchemaChange.Target.AGGREGATE, old.name().keyspace, old.name().name, AbstractType.asCQLTypeStringList(old.argTypes()));
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget.Type in project cassandra by apache.
the class TargetParser method parse.
public static Pair<ColumnMetadata, IndexTarget.Type> parse(TableMetadata metadata, String target) {
// if the regex matches then the target is in the form "keys(foo)", "entries(bar)" etc
// if not, then it must be a simple column name and implictly its type is VALUES
Matcher matcher = TARGET_REGEX.matcher(target);
String columnName;
IndexTarget.Type targetType;
if (matcher.matches()) {
targetType = IndexTarget.Type.fromString(matcher.group(1));
columnName = matcher.group(2);
} else {
columnName = target;
targetType = IndexTarget.Type.VALUES;
}
// need to un-escape any such quotes to get the actual column name
if (columnName.startsWith(QUOTE)) {
columnName = StringUtils.substring(StringUtils.substring(columnName, 1), 0, -1);
columnName = TWO_QUOTES.matcher(columnName).replaceAll(QUOTE);
}
// if it's not a CQL table, we can't assume that the column name is utf8, so
// in that case we have to do a linear scan of the cfm's columns to get the matching one.
// After dropping compact storage (see CASSANDRA-10857), we can't distinguish between the
// former compact/thrift table, so we have to fall back to linear scan in both cases.
ColumnMetadata cd = metadata.getColumn(new ColumnIdentifier(columnName, true));
if (cd != null)
return Pair.create(cd, targetType);
for (ColumnMetadata column : metadata.columns()) if (column.name.toString().equals(columnName))
return Pair.create(column, targetType);
return null;
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget.Type in project cassandra by apache.
the class NativeSSTableLoaderClient method createDefinitionFromRow.
private static ColumnMetadata createDefinitionFromRow(Row row, String keyspace, String table, Types types) {
ClusteringOrder order = ClusteringOrder.valueOf(row.getString("clustering_order").toUpperCase());
AbstractType<?> type = CQLTypeParser.parse(keyspace, row.getString("type"), types);
if (order == ClusteringOrder.DESC)
type = ReversedType.getInstance(type);
ColumnIdentifier name = new ColumnIdentifier(row.getBytes("column_name_bytes"), row.getString("column_name"));
int position = row.getInt("position");
org.apache.cassandra.schema.ColumnMetadata.Kind kind = ColumnMetadata.Kind.valueOf(row.getString("kind").toUpperCase());
return new ColumnMetadata(keyspace, table, name, type, position, kind);
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget.Type in project cassandra by apache.
the class BinAuditLoggerTest method testSelectRoundTripQuery.
@Test
public void testSelectRoundTripQuery() throws Throwable {
createTable("CREATE TABLE %s (id int primary key, v1 text, v2 text)");
execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 1, "Apache", "Cassandra");
execute("INSERT INTO %s (id, v1, v2) VALUES (?, ?, ?)", 2, "trace", "test");
String cql = "SELECT id, v1, v2 FROM " + KEYSPACE + '.' + currentTable() + " WHERE id = ?";
Session session = sessionNet();
PreparedStatement pstmt = session.prepare(cql);
ResultSet rs = session.execute(pstmt.bind(1));
assertEquals(1, rs.all().size());
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tempDir.toFile()).rollCycle(RollCycles.TEST_SECONDLY).build()) {
ExcerptTailer tailer = queue.createTailer();
assertTrue(tailer.readDocument(wire -> {
assertEquals(0L, wire.read("version").int16());
assertEquals("audit", wire.read("type").text());
assertThat(wire.read("message").text(), containsString(AuditLogEntryType.PREPARE_STATEMENT.toString()));
}));
assertTrue(tailer.readDocument(wire -> {
assertEquals(0L, wire.read("version").int16());
assertEquals("audit", wire.read("type").text());
assertThat(wire.read("message").text(), containsString(AuditLogEntryType.SELECT.toString()));
}));
assertFalse(tailer.readDocument(wire -> {
}));
}
}
use of org.apache.cassandra.cql3.statements.schema.IndexTarget.Type in project cassandra by apache.
the class BytesConversionFcts method all.
public static Collection<Function> all() {
Collection<Function> functions = new ArrayList<>();
// for varchar, so we special case it below. We also skip blob for obvious reasons.
for (CQL3Type type : CQL3Type.Native.values()) {
if (type != CQL3Type.Native.VARCHAR && type != CQL3Type.Native.BLOB) {
functions.add(makeToBlobFunction(type.getType()));
functions.add(makeFromBlobFunction(type.getType()));
}
}
functions.add(VarcharAsBlobFct);
functions.add(BlobAsVarcharFct);
return functions;
}
Aggregations