ExpressionAnalyzer extends AbstractNodeVisitor<Expression, AnalysisContext> { public Expression analyze(UnresolvedExpression unresolved, AnalysisContext context) { return unresolved.accept(this, context); } ExpressionAnalyzer(
      BuiltinFunctionRepository repository); Expression analyze(UnresolvedExpression unresolved, AnalysisContext context); @Override Expression visitUnresolvedAttribute(UnresolvedAttribute node, AnalysisContext context); @Override Expression visitEqualTo(EqualTo node, AnalysisContext context); @Override Expression visitLiteral(Literal node, AnalysisContext context); @Override Expression visitInterval(Interval node, AnalysisContext context); @Override Expression visitAnd(And node, AnalysisContext context); @Override Expression visitOr(Or node, AnalysisContext context); @Override Expression visitXor(Xor node, AnalysisContext context); @Override Expression visitNot(Not node, AnalysisContext context); @Override Expression visitAggregateFunction(AggregateFunction node, AnalysisContext context); @Override Expression visitFunction(Function node, AnalysisContext context); @Override Expression visitCompare(Compare node, AnalysisContext context); @Override Expression visitField(Field node, AnalysisContext context); @Override Expression visitQualifiedName(QualifiedName node, AnalysisContext context);  }
@Test public void qualified_name_with_qualifier() { analysisContext.push(); analysisContext.peek().define(new Symbol(Namespace.INDEX_NAME, "index_alias"), STRUCT); assertAnalyzeEqual( DSL.ref("integer_value", INTEGER), AstDSL.qualifiedName("index_alias", "integer_value") ); analysisContext.peek().define(new Symbol(Namespace.FIELD_NAME, "nested_field"), STRUCT); SyntaxCheckException exception = assertThrows(SyntaxCheckException.class, () -> analyze(AstDSL.qualifiedName("nested_field", "integer_value"))); assertEquals( "The qualifier [nested_field] of qualified name [nested_field.integer_value] " + "must be an index name or its alias", exception.getMessage() ); analysisContext.pop(); }
@Test public void skip_struct_data_type() { SyntaxCheckException exception = assertThrows(SyntaxCheckException.class, () -> analyze(AstDSL.qualifiedName("struct_value"))); assertEquals( "Identifier [struct_value] of type [STRUCT] is not supported yet", exception.getMessage() ); }
@Test public void skip_array_data_type() { SyntaxCheckException exception = assertThrows(SyntaxCheckException.class, () -> analyze(AstDSL.qualifiedName("array_value"))); assertEquals( "Identifier [array_value] of type [ARRAY] is not supported yet", exception.getMessage() ); }
@Test public void undefined_var_semantic_check_failed() { SemanticCheckException exception = assertThrows(SemanticCheckException.class, () -> analyze( AstDSL.and(AstDSL.unresolvedAttr("undefined_field"), AstDSL.booleanLiteral(true)))); assertEquals("can't resolve Symbol(namespace=FIELD_NAME, name=undefined_field) in type env", exception.getMessage()); }
@Test public void undefined_aggregation_function() { SemanticCheckException exception = assertThrows(SemanticCheckException.class, () -> analyze(AstDSL.aggregate("ESTDC_ERROR", field("integer_value")))); assertEquals("Unsupported aggregation function ESTDC_ERROR", exception.getMessage()); }