Search in sources :

Example 56 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class PercentileAggregationTest method testReturnTypes.

@Test
public void testReturnTypes() throws Exception {
    FunctionIdent synopsis1 = new FunctionIdent(NAME, ImmutableList.<DataType>of(DataTypes.DOUBLE, DataTypes.DOUBLE));
    assertEquals(DataTypes.DOUBLE, functions.get(synopsis1).info().returnType());
    FunctionIdent synopsis2 = new FunctionIdent(NAME, ImmutableList.<DataType>of(DataTypes.DOUBLE, new ArrayType(DataTypes.DOUBLE)));
    assertEquals(new ArrayType(DataTypes.DOUBLE), functions.get(synopsis2).info().returnType());
}
Also used : ArrayType(io.crate.types.ArrayType) FunctionIdent(io.crate.metadata.FunctionIdent) Test(org.junit.Test) AggregationTest(io.crate.operation.aggregation.AggregationTest)

Example 57 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class CompoundLiteralTest method testNestedArrayLiteral.

@Test
public void testNestedArrayLiteral() throws Exception {
    Map<String, DataType<?>> expected = Map.of("'string'", DataTypes.STRING, "0", DataTypes.INTEGER, "1.8", DataTypes.DOUBLE, "TRUE", DataTypes.BOOLEAN);
    for (Map.Entry<String, DataType<?>> entry : expected.entrySet()) {
        Symbol nestedArraySymbol = analyzeExpression("[[" + entry.getKey() + "]]");
        assertThat(nestedArraySymbol, Matchers.instanceOf(Literal.class));
        Literal<?> nestedArray = (Literal<?>) nestedArraySymbol;
        assertThat(nestedArray.valueType(), is(new ArrayType<>(new ArrayType<>(entry.getValue()))));
    }
}
Also used : ArrayType(io.crate.types.ArrayType) Symbol(io.crate.expression.symbol.Symbol) Literal(io.crate.expression.symbol.Literal) DataType(io.crate.types.DataType) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 58 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class DataTypeAnalyzerTest method testCastToNestedArrayExpressionReturnsArrayType.

@Test
public void testCastToNestedArrayExpressionReturnsArrayType() {
    Cast cast = (Cast) SqlParser.createExpression("xs::array(array(int))");
    DataType<?> dataType = DataTypeAnalyzer.convert(cast.getType());
    assertThat(dataType, is(new ArrayType<>(new ArrayType<>(DataTypes.INTEGER))));
}
Also used : Cast(io.crate.sql.tree.Cast) ArrayType(io.crate.types.ArrayType) Test(org.junit.Test)

Example 59 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class DataTypeTest method testForValueWithEmptyList.

@Test
public void testForValueWithEmptyList() {
    List<Object> objects = Arrays.<Object>asList();
    DataType type = DataTypes.guessType(objects);
    assertEquals(type, new ArrayType(DataTypes.UNDEFINED));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test)

Example 60 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class DataTypeTest method testForValueWithTimestampArrayAsString.

@Test
public void testForValueWithTimestampArrayAsString() {
    String[] strings = { "2013-09-10T21:51:43", "2013-11-10T21:51:43" };
    DataType dataType = DataTypes.guessType(strings);
    assertEquals(dataType, new ArrayType(DataTypes.STRING));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test)

Aggregations

ArrayType (io.crate.types.ArrayType)76 Test (org.junit.Test)53 DataType (io.crate.types.DataType)35 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)15 Symbol (io.crate.expression.symbol.Symbol)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 BytesRef (org.apache.lucene.util.BytesRef)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)7 Literal (io.crate.analyze.symbol.Literal)6 Literal (io.crate.expression.symbol.Literal)6 ColumnIdent (io.crate.metadata.ColumnIdent)6 Input (io.crate.data.Input)5 HashMap (java.util.HashMap)5 Function (io.crate.analyze.symbol.Function)4 Reference (io.crate.metadata.Reference)4 DataTypes (io.crate.types.DataTypes)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 TransactionContext (io.crate.metadata.TransactionContext)3