Search in sources :

Example 1 with ColumnValue

use of org.apache.calcite.avatica.proto.Common.ColumnValue in project calcite-avatica by apache.

the class FrameTest method testColumnValueParsing.

@Test
public void testColumnValueParsing() {
    // 1
    final ColumnValue scalarValue = ColumnValue.newBuilder().setScalarValue(NUMBER_VALUE).build();
    // [1, 1]
    final ColumnValue arrayValue = ColumnValue.newBuilder().addArrayValue(NUMBER_VALUE).addArrayValue(NUMBER_VALUE).setHasArrayValue(true).build();
    assertTrue(Frame.isNewStyleColumn(scalarValue));
    assertTrue(Frame.isNewStyleColumn(arrayValue));
    Object scalar = Frame.parseColumn(scalarValue);
    assertEquals(1L, scalar);
    Object array = Frame.parseColumn(arrayValue);
    assertEquals(Arrays.asList(1L, 1L), array);
}
Also used : ColumnValue(org.apache.calcite.avatica.proto.Common.ColumnValue) Test(org.junit.Test)

Example 2 with ColumnValue

use of org.apache.calcite.avatica.proto.Common.ColumnValue in project calcite-avatica by apache.

the class FrameTest method testMalformedColumnValue.

@Test
public void testMalformedColumnValue() {
    // Invalid ColumnValue: has an array and scalar
    final ColumnValue bothAttributesColumnValue = ColumnValue.newBuilder().setHasArrayValue(true).setScalarValue(NUMBER_VALUE).build();
    // Note omission of setScalarValue(TypedValue).
    final ColumnValue neitherAttributeColumnValue = ColumnValue.newBuilder().setHasArrayValue(false).build();
    try {
        Frame.validateColumnValue(bothAttributesColumnValue);
        fail("Validating the ColumnValue should have failed as it has an array and scalar");
    } catch (IllegalArgumentException e) {
    // Pass
    }
    try {
        Frame.validateColumnValue(neitherAttributeColumnValue);
        fail("Validating the ColumnValue should have failed as it has neither an array nor scalar");
    } catch (IllegalArgumentException e) {
    // Pass
    }
}
Also used : ColumnValue(org.apache.calcite.avatica.proto.Common.ColumnValue) Test(org.junit.Test)

Example 3 with ColumnValue

use of org.apache.calcite.avatica.proto.Common.ColumnValue in project calcite-avatica by apache.

the class FrameTest method testColumnValueBackwardsCompatibility.

@Test
public void testColumnValueBackwardsCompatibility() {
    // 1
    final ColumnValue oldStyleScalarValue = ColumnValue.newBuilder().addValue(NUMBER_VALUE).build();
    // [1, 1]
    final ColumnValue oldStyleArrayValue = ColumnValue.newBuilder().addValue(NUMBER_VALUE).addValue(NUMBER_VALUE).build();
    assertFalse(Frame.isNewStyleColumn(oldStyleScalarValue));
    assertFalse(Frame.isNewStyleColumn(oldStyleArrayValue));
    Object scalar = Frame.parseOldStyleColumn(oldStyleScalarValue);
    assertEquals(1L, scalar);
    Object array = Frame.parseOldStyleColumn(oldStyleArrayValue);
    assertEquals(Arrays.asList(1L, 1L), array);
}
Also used : ColumnValue(org.apache.calcite.avatica.proto.Common.ColumnValue) Test(org.junit.Test)

Aggregations

ColumnValue (org.apache.calcite.avatica.proto.Common.ColumnValue)3 Test (org.junit.Test)3