use of org.teiid.language.Command in project teiid by teiid.
the class TestImpalaExecutionFactory method testDistinctAggregate.
@Test
public void testDistinctAggregate() {
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand("SELECT distinct max(StringNum) FROM bqt1.SmallA group by stringkey");
SQLConversionVisitor sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT DISTINCT c_0 FROM (SELECT MAX(SmallA.StringNum) AS c_0 FROM SmallA GROUP BY SmallA.StringKey) X__", sqlVisitor.toString());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestImpalaExecutionFactory method testOrderedUnion.
@Test
public void testOrderedUnion() {
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand("SELECT g_1.StringNum AS c_0 FROM bqt1.SmallA AS g_1 WHERE g_1.IntKey <= 50 UNION ALL SELECT g_0.StringNum AS c_0 FROM bqt1.SmallB AS g_0 WHERE g_0.IntKey > 50 ORDER BY c_0 limit 10");
SQLConversionVisitor sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT c_0 FROM (SELECT g_1.StringNum AS c_0 FROM SmallA g_1 WHERE g_1.IntKey <= 50 UNION ALL SELECT g_0.StringNum AS c_0 FROM SmallB g_0 WHERE g_0.IntKey > 50) X__ ORDER BY c_0 LIMIT 10", sqlVisitor.toString());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestImpalaExecutionFactory method testMultipleDistinctAggregates.
@Test
public void testMultipleDistinctAggregates() {
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.example1Cached());
Command obj = commandBuilder.getCommand("select count(distinct pm1.g1.e1), 1, count(distinct pm1.g1.e2), avg(distinct pm1.g1.e4) from pm1.g1");
SQLConversionVisitor sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT v0.c0, v0.c1, v1.c2, v2.c3 FROM (SELECT COUNT(DISTINCT g1.e1) AS c0, 1 AS c1 FROM g1) v0 CROSS JOIN (SELECT COUNT(DISTINCT g1.e2) AS c2 FROM g1) v1 CROSS JOIN (SELECT AVG(DISTINCT g1.e4) AS c3 FROM g1) v2", sqlVisitor.toString());
obj = commandBuilder.getCommand("select count(distinct pm1.g1.e1), 1, count(distinct pm1.g1.e2), avg(distinct pm1.g1.e4) from pm1.g1 where pm1.g1.e3 = true");
sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT v0.c0, v0.c1, v1.c2, v2.c3 FROM (SELECT COUNT(DISTINCT g1.e1) AS c0, 1 AS c1 FROM g1 WHERE g1.e3 = true) v0 CROSS JOIN (SELECT COUNT(DISTINCT g1.e2) AS c2 FROM g1 WHERE g1.e3 = true) v1 CROSS JOIN (SELECT AVG(DISTINCT g1.e4) AS c3 FROM g1 WHERE g1.e3 = true) v2", sqlVisitor.toString());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestTranslationUtility method helpTestTranslate.
public void helpTestTranslate(String sql, String expectedOutput) {
TranslationUtility util = new TranslationUtility(getTestVDB());
Command query = util.parseCommand(sql);
assertEquals(expectedOutput, query.toString());
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestExcelExecution method helpExecute.
private ArrayList helpExecute(String ddl, FileConnection connection, String query, boolean format) throws Exception {
ExcelExecutionFactory translator = new ExcelExecutionFactory();
translator.setFormatStrings(format);
translator.start();
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "vdb", "excel");
TranslationUtility utility = new TranslationUtility(metadata);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
ResultSetExecution execution = translator.createResultSetExecution((QueryExpression) cmd, context, utility.createRuntimeMetadata(), connection);
try {
execution.execute();
ArrayList results = new ArrayList();
while (true) {
List<?> row = execution.next();
if (row == null) {
break;
}
results.add(row);
}
return results;
} finally {
execution.close();
}
}
Aggregations