use of io.crate.types.DataType in project crate by crate.
the class SelectStatementAnalyzerTest method testILikeInWhereQuery.
@Test
public void testILikeInWhereQuery() {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select * from sys.nodes where name ilike 'foo%'");
assertNotNull(relation.where());
Function whereClause = (Function) relation.where();
assertThat(whereClause.name(), is(LikeOperators.OP_ILIKE));
List<DataType> argumentTypes = List.of(DataTypes.STRING, DataTypes.STRING);
assertEquals(argumentTypes, Symbols.typeView(whereClause.arguments()));
assertThat(whereClause.arguments().get(0), isReference("name"));
assertThat(whereClause.arguments().get(1), isLiteral("foo%"));
}
use of io.crate.types.DataType in project crate by crate.
the class SelectStatementAnalyzerTest method testLikeInWhereQuery.
@Test
public void testLikeInWhereQuery() {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select * from sys.nodes where name like 'foo'");
assertNotNull(relation.where());
Function whereClause = (Function) relation.where();
assertThat(whereClause.name(), is(LikeOperators.OP_LIKE));
List<DataType> argumentTypes = List.of(DataTypes.STRING, DataTypes.STRING);
assertEquals(argumentTypes, Symbols.typeView(whereClause.arguments()));
assertThat(whereClause.arguments().get(0), isReference("name"));
assertThat(whereClause.arguments().get(1), isLiteral("foo"));
}
use of io.crate.types.DataType in project crate by crate.
the class SelectStatementAnalyzerTest method testLikeNoStringDataTypeInWhereQuery.
@Test
public void testLikeNoStringDataTypeInWhereQuery() {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select * from sys.nodes where name like 1");
// check if the implicit cast of the pattern worked
List<DataType> argumentTypes = List.of(DataTypes.STRING, DataTypes.STRING);
Function whereClause = (Function) relation.where();
assertEquals(argumentTypes, Symbols.typeView(whereClause.arguments()));
assertThat(whereClause.arguments().get(1), IsInstanceOf.instanceOf(Literal.class));
Literal stringLiteral = (Literal) whereClause.arguments().get(1);
assertThat(stringLiteral.value(), is("1"));
}
use of io.crate.types.DataType in project crate by crate.
the class PGTypesTest method testCrateCollection2PgType.
@Test
public void testCrateCollection2PgType() {
for (DataType type : PRIMITIVE_TYPES) {
assertThat(PGTypes.get(new ArrayType(type)), instanceOf(PGArray.class));
}
assertThat(PGTypes.get(new ArrayType(GEO_POINT)), instanceOf(PGArray.class));
assertThat(PGTypes.get(new ArrayType(GEO_SHAPE)), instanceOf(PGArray.class));
}
use of io.crate.types.DataType in project crate by crate.
the class Session method analyze.
public void analyze(String statementName, Statement statement, List<DataType> paramTypes, @Nullable String query) {
AnalyzedStatement analyzedStatement;
DataType[] parameterTypes;
try {
analyzedStatement = analyzer.analyze(statement, sessionContext, new ParamTypeHints(paramTypes));
parameterTypes = parameterTypeExtractor.getParameterTypes(x -> Relations.traverseDeepSymbols(analyzedStatement, x));
} catch (Throwable t) {
jobsLogs.logPreExecutionFailure(UUIDs.dirtyUUID(), query == null ? statementName : query, SQLExceptions.messageOf(t), sessionContext.sessionUser());
throw t;
}
preparedStatements.put(statementName, new PreparedStmt(statement, analyzedStatement, query, parameterTypes));
}
Aggregations