### Question:
QueryAnalyzer { public Analysis analyze(final String sqlExpression, final Query query) { Analysis analysis = new Analysis(); Analyzer analyzer = new Analyzer(sqlExpression, analysis, metaStore); analyzer.process(query, new AnalysisContext()); return analysis; } QueryAnalyzer(final MetaStore metaStore, final FunctionRegistry functionRegistry); Analysis analyze(final String sqlExpression, final Query query); AggregateAnalysis analyzeAggregate(final Query query, final Analysis analysis);  }### Answer:
@Test public void shouldCreateAnalysisForSimpleQuery() { final List<Statement> statements = ksqlParser.buildAst("select orderid from orders;", metaStore); final Analysis analysis = queryAnalyzer.analyze("sqlExpression", (Query)statements.get(0)); final Pair<StructuredDataSource, String> fromDataSource = analysis.getFromDataSource(0); assertThat(analysis.getSelectExpressions(), equalTo( Collections.singletonList(new DereferenceExpression( new QualifiedNameReference(QualifiedName.of("ORDERS")), "ORDERID")))); assertThat(analysis.getFromDataSources().size(), equalTo(1)); assertThat(fromDataSource.left, instanceOf(KsqlStream.class)); assertThat(fromDataSource.right, equalTo("ORDERS")); }
@Test public void shouldFailWithIncorrectJoinCriteria() { final List<Statement> statements = ksqlParser.buildAst( "select * from test1 join test2 on test1.col1 = test2.coll;", metaStore); final Query query = (Query) statements.get(0); try { queryAnalyzer.analyze("sqlExpression", query); } catch (KsqlException ex) { assertThat(ex.getMessage().trim(), equalTo("Line: 1, Col: 46 : Invalid join criteria (TEST1.COL1 = TEST2.COLL). Key for TEST2 is not set correctly.")); } }
@Test public void shouldPassJoinWithAnyCriteriaOrder() { final List<Statement> statements = ksqlParser.buildAst( "select * from test1 left join test2 on test2.col2 = test1.col1;", metaStore); final Query query = (Query) statements.get(0); final Analysis analysis = queryAnalyzer.analyze("sqlExpression", query); assertTrue(analysis.getJoin().isLeftJoin()); assertThat(analysis.getJoin().getLeftKeyFieldName(), equalTo("COL1")); assertThat(analysis.getJoin().getRightKeyFieldName(), equalTo("COL2")); }