use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestHiveExecutionFactory method helpTestVisitor.
private void helpTestVisitor(QueryMetadataInterface metadata, String input, String expectedOutput) throws TranslatorException {
// Convert from sql to objects
CommandBuilder commandBuilder = new CommandBuilder(metadata);
Command obj = commandBuilder.getCommand(input);
// Convert back to SQL
TranslatedCommand tc = new TranslatedCommand(Mockito.mock(ExecutionContext.class), hiveTranslator);
tc.translateCommand(obj);
// Check stuff
// $NON-NLS-1$
assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestImpalaExecutionFactory method testWith.
@Test
public void testWith() {
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Select obj = (Select) commandBuilder.getCommand("with x as /*+ no_inline */ (SELECT max(StringNum) as a FROM bqt1.SmallA group by stringkey) select * from x");
SQLConversionVisitor sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("WITH x AS (SELECT MAX(SmallA.StringNum) AS a FROM SmallA GROUP BY SmallA.StringKey) SELECT x.a FROM x", sqlVisitor.toString());
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestImpalaExecutionFactory method testOffset.
@Test
public void testOffset() {
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.example1Cached());
Command obj = commandBuilder.getCommand("select pm1.g1.e2 from pm1.g1 limit 1, 2");
SQLConversionVisitor sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT g1.e2 FROM g1 ORDER BY 1 LIMIT 2 OFFSET 1", sqlVisitor.toString());
obj = commandBuilder.getCommand("select pm1.g1.e2, pm1.g1.e1 from pm1.g1 order by e1 limit 1, 100");
sqlVisitor = impalaTranslator.getSQLConversionVisitor();
sqlVisitor.append(obj);
assertEquals("SELECT g1.e2, g1.e1 FROM g1 ORDER BY e1 LIMIT 100 OFFSET 1", sqlVisitor.toString());
}
use of org.teiid.cdk.CommandBuilder 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.cdk.CommandBuilder 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());
}
Aggregations