use of com.datastax.oss.driver.api.core.metadata.schema.AggregateMetadata in project java-driver by datastax.
the class AggregateParserTest method should_parse_modern_table.
@Test
public void should_parse_modern_table() {
AggregateParser parser = new AggregateParser(new DataTypeCqlNameParser(), context);
AggregateMetadata aggregate = parser.parseAggregate(SUM_AND_TO_STRING_ROW_3_0, KEYSPACE_ID, Collections.emptyMap());
assertThat(aggregate.getKeyspace().asInternal()).isEqualTo("ks");
assertThat(aggregate.getSignature().getName().asInternal()).isEqualTo("sum_and_to_string");
assertThat(aggregate.getSignature().getParameterTypes()).containsExactly(DataTypes.INT);
FunctionSignature stateFuncSignature = aggregate.getStateFuncSignature();
assertThat(stateFuncSignature.getName().asInternal()).isEqualTo("plus");
assertThat(stateFuncSignature.getParameterTypes()).containsExactly(DataTypes.INT, DataTypes.INT);
assertThat(aggregate.getStateType()).isEqualTo(DataTypes.INT);
Optional<FunctionSignature> finalFuncSignature = aggregate.getFinalFuncSignature();
assertThat(finalFuncSignature).isPresent();
assertThat(finalFuncSignature).hasValueSatisfying(signature -> {
assertThat(signature.getName().asInternal()).isEqualTo("to_string");
assertThat(signature.getParameterTypes()).containsExactly(DataTypes.INT);
});
assertThat(aggregate.getReturnType()).isEqualTo(DataTypes.TEXT);
assertThat(aggregate.getInitCond().get()).isInstanceOf(Integer.class).isEqualTo(0);
}
use of com.datastax.oss.driver.api.core.metadata.schema.AggregateMetadata in project java-driver by datastax.
the class AggregateParserTest method should_parse_legacy_table.
@Test
public void should_parse_legacy_table() {
AggregateParser parser = new AggregateParser(new DataTypeClassNameParser(), context);
AggregateMetadata aggregate = parser.parseAggregate(SUM_AND_TO_STRING_ROW_2_2, KEYSPACE_ID, Collections.emptyMap());
assertThat(aggregate.getKeyspace().asInternal()).isEqualTo("ks");
assertThat(aggregate.getSignature().getName().asInternal()).isEqualTo("sum_and_to_string");
assertThat(aggregate.getSignature().getParameterTypes()).containsExactly(DataTypes.INT);
FunctionSignature stateFuncSignature = aggregate.getStateFuncSignature();
assertThat(stateFuncSignature.getName().asInternal()).isEqualTo("plus");
assertThat(stateFuncSignature.getParameterTypes()).containsExactly(DataTypes.INT, DataTypes.INT);
assertThat(aggregate.getStateType()).isEqualTo(DataTypes.INT);
Optional<FunctionSignature> finalFuncSignature = aggregate.getFinalFuncSignature();
assertThat(finalFuncSignature).isPresent();
assertThat(finalFuncSignature).hasValueSatisfying(signature -> {
assertThat(signature.getName().asInternal()).isEqualTo("to_string");
assertThat(signature.getParameterTypes()).containsExactly(DataTypes.INT);
});
assertThat(aggregate.getReturnType()).isEqualTo(DataTypes.TEXT);
assertThat(aggregate.getInitCond().get()).isInstanceOf(Integer.class).isEqualTo(0);
}
use of com.datastax.oss.driver.api.core.metadata.schema.AggregateMetadata in project java-driver by datastax.
the class DseAggregateParser method parseAggregate.
public DseAggregateMetadata parseAggregate(AdminRow row, CqlIdentifier keyspaceId, Map<CqlIdentifier, UserDefinedType> userDefinedTypes) {
AggregateMetadata aggregate = aggregateParser.parseAggregate(row, keyspaceId, userDefinedTypes);
// parse the DSE extended columns
final Boolean deterministic = row.contains("deterministic") ? row.getBoolean("deterministic") : null;
return new DefaultDseAggregateMetadata(aggregate.getKeyspace(), aggregate.getSignature(), aggregate.getFinalFuncSignature().orElse(null), aggregate.getInitCond().orElse(null), aggregate.getReturnType(), aggregate.getStateFuncSignature(), aggregate.getStateType(), context.getCodecRegistry().codecFor(aggregate.getStateType()), deterministic);
}
Aggregations