Search in sources :

Example 1 with FullQualifedNameFieldProvider

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());
}
Also used : SymbolMatchers.isField(io.crate.testing.SymbolMatchers.isField) Field(io.crate.analyze.symbol.Field) SessionContext(io.crate.action.sql.SessionContext) FullQualifedNameFieldProvider(io.crate.analyze.relations.FullQualifedNameFieldProvider) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with FullQualifedNameFieldProvider

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());
}
Also used : Function(io.crate.analyze.symbol.Function) SessionContext(io.crate.action.sql.SessionContext) FullQualifedNameFieldProvider(io.crate.analyze.relations.FullQualifedNameFieldProvider) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with FullQualifedNameFieldProvider

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);
}
Also used : FullQualifedNameFieldProvider(io.crate.analyze.relations.FullQualifedNameFieldProvider) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

FullQualifedNameFieldProvider (io.crate.analyze.relations.FullQualifedNameFieldProvider)3 CrateUnitTest (io.crate.test.integration.CrateUnitTest)3 Test (org.junit.Test)3 SessionContext (io.crate.action.sql.SessionContext)2 Field (io.crate.analyze.symbol.Field)1 Function (io.crate.analyze.symbol.Function)1 SymbolMatchers.isField (io.crate.testing.SymbolMatchers.isField)1