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));
}
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);
}
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));
}
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);
}
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));
}
Aggregations