use of io.crate.types.ArrayType in project crate by crate.
the class UpdateAnalyzerTest method testUpdateElementOfObjectArrayUsingParameterExpressionInsideFunctionResultsInCorrectlyTypedParameterSymbol.
@Test
public void testUpdateElementOfObjectArrayUsingParameterExpressionInsideFunctionResultsInCorrectlyTypedParameterSymbol() {
AnalyzedUpdateStatement stmt = e.analyze("UPDATE bag SET ob = array_cat([?], [{obb=1}]) WHERE id = ?");
assertThat(stmt.assignmentByTargetCol().keySet(), contains(isReference("ob", new ArrayType(DataTypes.UNTYPED_OBJECT))));
assertThat(stmt.assignmentByTargetCol().values(), contains(isFunction("array_cat", isFunction("_array", singletonList(DataTypes.UNTYPED_OBJECT)), instanceOf(Literal.class))));
}
use of io.crate.types.ArrayType in project crate by crate.
the class SelectStatementAnalyzerTest method testCastToNestedArrayCanBeUsed.
@Test
public void testCastToNestedArrayCanBeUsed() {
var executor = SQLExecutor.builder(clusterService).build();
AnalyzedRelation relation = executor.analyze("select [[1, 2, 3]]::array(array(int))");
assertThat(relation.outputs().get(0).valueType(), is(new ArrayType<>(DataTypes.INTEGER_ARRAY)));
}
use of io.crate.types.ArrayType in project crate by crate.
the class SelectStatementAnalyzerTest method testAnyOnObjectArrayField.
@Test
public void testAnyOnObjectArrayField() throws Exception {
var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
QueriedSelectRelation relation = executor.analyze("select * from users where 5 = ANY (friends['id'])");
Function anyFunction = (Function) relation.where();
assertThat(anyFunction.name(), is(AnyEqOperator.NAME));
assertThat(anyFunction.arguments().get(1), isReference("friends['id']", new ArrayType<>(DataTypes.LONG)));
assertThat(anyFunction.arguments().get(0), isLiteral(5L));
}
use of io.crate.types.ArrayType in project crate by crate.
the class CreateFunctionAnalyzerTest method testCreateFunctionWithComplexComplexTypes.
@Test
public void testCreateFunctionWithComplexComplexTypes() {
AnalyzedStatement analyzedStatement = e.analyze("CREATE FUNCTION" + " bar(array(integer)," + " object, ip," + " timestamp with time zone" + ") RETURNS array(geo_point) LANGUAGE dummy_lang AS 'function() { return 1; }'");
assertThat(analyzedStatement, instanceOf(AnalyzedCreateFunction.class));
AnalyzedCreateFunction analysis = (AnalyzedCreateFunction) analyzedStatement;
assertThat(analysis.name(), is("bar"));
assertThat(analysis.replace(), is(false));
assertThat(analysis.returnType(), is(new ArrayType(DataTypes.GEO_POINT)));
assertThat(analysis.arguments().get(0), is(FunctionArgumentDefinition.of(new ArrayType(DataTypes.INTEGER))));
assertThat(analysis.arguments().get(1), is(FunctionArgumentDefinition.of(DataTypes.UNTYPED_OBJECT)));
assertThat(analysis.arguments().get(2), is(FunctionArgumentDefinition.of(DataTypes.IP)));
assertThat(analysis.arguments().get(3), is(FunctionArgumentDefinition.of(DataTypes.TIMESTAMPZ)));
assertThat(analysis.language(), is(Literal.of("dummy_lang")));
}
use of io.crate.types.ArrayType in project crate by crate.
the class ArrayMaxFunctionTest method test_array_returns_max_element.
@Test
public void test_array_returns_max_element() {
List<DataType> typesToTest = new ArrayList(DataTypes.PRIMITIVE_TYPES);
typesToTest.add(DataTypes.NUMERIC);
for (DataType type : typesToTest) {
var valuesToTest = TestingHelpers.getRandomsOfType(2, 10, type);
var optional = valuesToTest.stream().filter(o -> o != null).max((o1, o2) -> type.compare(o1, o2));
var expected = optional.orElse(null);
String expression = String.format(Locale.ENGLISH, "array_max(?::%s[])", type.getName());
assertEvaluate(expression, expected, Literal.of(valuesToTest, new ArrayType<>(type)));
}
}
Aggregations