Search in sources :

Example 1 with AggregateMetadata

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);
}
Also used : AggregateMetadata(com.datastax.oss.driver.api.core.metadata.schema.AggregateMetadata) FunctionSignature(com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature) Test(org.junit.Test)

Example 2 with AggregateMetadata

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);
}
Also used : AggregateMetadata(com.datastax.oss.driver.api.core.metadata.schema.AggregateMetadata) FunctionSignature(com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature) Test(org.junit.Test)

Example 3 with AggregateMetadata

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);
}
Also used : DefaultDseAggregateMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseAggregateMetadata) AggregateMetadata(com.datastax.oss.driver.api.core.metadata.schema.AggregateMetadata) DseAggregateMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseAggregateMetadata) DefaultDseAggregateMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseAggregateMetadata)

Aggregations

AggregateMetadata (com.datastax.oss.driver.api.core.metadata.schema.AggregateMetadata)3 FunctionSignature (com.datastax.oss.driver.api.core.metadata.schema.FunctionSignature)2 Test (org.junit.Test)2 DseAggregateMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseAggregateMetadata)1 DefaultDseAggregateMetadata (com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseAggregateMetadata)1