Search in sources :

Example 6 with ArrayType

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

the class MetaDataToASTNodeResolverTest method testBuildCreateTableColumns.

@Test
public void testBuildCreateTableColumns() throws Exception {
    TableIdent ident = new TableIdent("doc", "test");
    List<Reference> columns = ImmutableList.of(newReference(ident, "bools", DataTypes.BOOLEAN), newReference(ident, "bytes", DataTypes.BYTE), newReference(ident, "strings", DataTypes.STRING), newReference(ident, "shorts", DataTypes.SHORT), newReference(ident, "floats", DataTypes.FLOAT), newReference(ident, "doubles", DataTypes.DOUBLE), newReference(ident, "ints", DataTypes.INTEGER), newReference(ident, "longs", DataTypes.LONG), newReference(ident, "timestamp", DataTypes.TIMESTAMP), newReference(ident, "ip_addr", DataTypes.IP), newReference(ident, "arr_simple", new ArrayType(DataTypes.STRING)), newReference(ident, "arr_geo_point", new ArrayType(DataTypes.GEO_POINT)), newReference(ident, "arr_obj", new ArrayType(DataTypes.OBJECT), null, ColumnPolicy.STRICT, false), newReference(ident, "arr_obj", DataTypes.LONG, Arrays.asList("col_1"), null, false), newReference(ident, "arr_obj", DataTypes.STRING, Arrays.asList("col_2"), null, false), newReference(ident, "obj", DataTypes.OBJECT, null, ColumnPolicy.DYNAMIC, false), newReference(ident, "obj", DataTypes.LONG, Arrays.asList("col_1"), null, false), newReference(ident, "obj", DataTypes.STRING, Arrays.asList("col_2"), null, false));
    DocTableInfo tableInfo = new TestDocTableInfo(ident, 5, "0-all", columns, ImmutableList.<Reference>of(), ImmutableList.<GeneratedReference>of(), ImmutableMap.<ColumnIdent, IndexReference>of(), referencesMap(columns), ImmutableMap.<ColumnIdent, String>of(), ImmutableList.<ColumnIdent>of(), null, ImmutableMap.<String, Object>of(), ImmutableList.<ColumnIdent>of(), ColumnPolicy.DYNAMIC);
    CreateTable node = MetaDataToASTNodeResolver.resolveCreateTable(tableInfo);
    assertEquals("CREATE TABLE IF NOT EXISTS \"doc\".\"test\" (\n" + "   \"bools\" BOOLEAN,\n" + "   \"bytes\" BYTE,\n" + "   \"strings\" STRING,\n" + "   \"shorts\" SHORT,\n" + "   \"floats\" FLOAT,\n" + "   \"doubles\" DOUBLE,\n" + "   \"ints\" INTEGER,\n" + "   \"longs\" LONG,\n" + "   \"timestamp\" TIMESTAMP,\n" + "   \"ip_addr\" IP,\n" + "   \"arr_simple\" ARRAY(STRING),\n" + "   \"arr_geo_point\" ARRAY(GEO_POINT),\n" + "   \"arr_obj\" ARRAY(OBJECT (STRICT) AS (\n" + "      \"col_1\" LONG,\n" + "      \"col_2\" STRING\n" + "   )),\n" + "   \"obj\" OBJECT (DYNAMIC) AS (\n" + "      \"col_1\" LONG,\n" + "      \"col_2\" STRING\n" + "   )\n" + ")\n" + "CLUSTERED INTO 5 SHARDS\n" + "WITH (\n" + "   column_policy = 'dynamic',\n" + "   number_of_replicas = '0-all'\n" + ")", SqlFormatter.formatSql(node));
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) CreateTable(io.crate.sql.tree.CreateTable) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with ArrayType

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

the class AnyLikeOperatorTest method anyLike.

private Boolean anyLike(String pattern, String... expressions) {
    Literal patternLiteral = Literal.of(pattern);
    Object[] value = new Object[expressions.length];
    for (int i = 0; i < expressions.length; i++) {
        value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
    }
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
    AnyLikeOperator impl = (AnyLikeOperator) new AnyLikeOperator.AnyLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    return impl.evaluate(patternLiteral, valuesLiteral);
}
Also used : ArrayType(io.crate.types.ArrayType) Literal(io.crate.analyze.symbol.Literal) BytesRef(org.apache.lucene.util.BytesRef)

Example 8 with ArrayType

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

the class AnyLikeOperatorTest method testNegateLike.

@Test
public void testNegateLike() throws Exception {
    Literal patternLiteral = Literal.of("A");
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("A"), new BytesRef("B") });
    FunctionImplementation impl = new AnyLikeOperator.AnyLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    Function anyLikeFunction = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    Input<Boolean> normalized = (Input<Boolean>) impl.normalizeSymbol(anyLikeFunction, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized.value(), is(true));
    assertThat(new NotPredicate().evaluate(normalized), is(false));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) FunctionImplementation(io.crate.metadata.FunctionImplementation) NotPredicate(io.crate.operation.predicate.NotPredicate) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with ArrayType

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

the class AnyNotLikeOperatorTest method anyNotLike.

private Boolean anyNotLike(String pattern, String... expressions) {
    Literal patternLiteral = Literal.of(pattern);
    Object[] value = new Object[expressions.length];
    for (int i = 0; i < expressions.length; i++) {
        value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
    }
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
    AnyNotLikeOperator impl = (AnyNotLikeOperator) new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    return impl.evaluate(patternLiteral, valuesLiteral);
}
Also used : ArrayType(io.crate.types.ArrayType) Literal(io.crate.analyze.symbol.Literal) BytesRef(org.apache.lucene.util.BytesRef)

Example 10 with ArrayType

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

the class AnyNotLikeOperatorTest method testNegateNotLike.

@Test
public void testNegateNotLike() throws Exception {
    Literal patternLiteral = Literal.of("A");
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("A"), new BytesRef("B") });
    FunctionImplementation impl = new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    Function anyNotLikeFunction = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    Input<Boolean> normalized = (Input<Boolean>) impl.normalizeSymbol(anyNotLikeFunction, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized.value(), is(true));
    assertThat(new NotPredicate().evaluate(normalized), is(false));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) FunctionImplementation(io.crate.metadata.FunctionImplementation) NotPredicate(io.crate.operation.predicate.NotPredicate) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

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