use of io.crate.analyze.relations.FullQualifedNameFieldProvider in project crate by crate.
the class ExpressionAnalyzerTest method testQuotedSubscriptExpression.
@Test
public void testQuotedSubscriptExpression() throws Exception {
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, new SessionContext(0, EnumSet.of(Option.ALLOW_QUOTED_SUBSCRIPT), null), paramTypeHints, new FullQualifedNameFieldProvider(dummySources), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
Field field1 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("obj['x']"), expressionAnalysisContext);
Field field2 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"obj['x']\""), expressionAnalysisContext);
assertEquals(field1, field2);
Field field3 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"myObj['x']\""), expressionAnalysisContext);
assertEquals("myObj['x']", field3.path().toString());
Field field4 = (Field) expressionAnalyzer.convert(SqlParser.createExpression("\"myObj['x']['AbC']\""), expressionAnalysisContext);
assertEquals("myObj['x']['AbC']", field4.path().toString());
}
use of io.crate.analyze.relations.FullQualifedNameFieldProvider in project crate by crate.
the class ExpressionAnalyzerTest method testAnalyzeSubscriptFunctionCall.
@Test
public void testAnalyzeSubscriptFunctionCall() throws Exception {
// Test when use subscript function is used explicitly then it's handled (and validated)
// the same way it's handled when the subscript operator `[]` is used
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, new SessionContext(0, EnumSet.of(Option.ALLOW_QUOTED_SUBSCRIPT), null), paramTypeHints, new FullQualifedNameFieldProvider(dummySources), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
FunctionCall subscriptFunctionCall = new FunctionCall(new QualifiedName("subscript"), ImmutableList.of(new ArrayLiteral(ImmutableList.of(new StringLiteral("obj"))), new LongLiteral("1")));
Function function = (Function) expressionAnalyzer.convert(subscriptFunctionCall, expressionAnalysisContext);
assertEquals("subscript(_array(Literal{obj, type=string}),Literal{1, type=integer})", function.toString());
}
use of io.crate.analyze.relations.FullQualifedNameFieldProvider in project crate by crate.
the class ExpressionAnalyzerTest method testUnsupportedExpressionCurrentDate.
@Test
public void testUnsupportedExpressionCurrentDate() throws Exception {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("Unsupported expression current_time");
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, SessionContext.SYSTEM_SESSION, paramTypeHints, new FullQualifedNameFieldProvider(dummySources), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
expressionAnalyzer.convert(SqlParser.createExpression("current_time"), expressionAnalysisContext);
}
Aggregations