Search in sources :

Example 1 with CommandBuilder

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());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CommandBuilder(org.teiid.cdk.CommandBuilder)

Example 2 with CommandBuilder

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());
}
Also used : SQLConversionVisitor(org.teiid.translator.jdbc.SQLConversionVisitor) Select(org.teiid.language.Select) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 3 with CommandBuilder

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());
}
Also used : SQLConversionVisitor(org.teiid.translator.jdbc.SQLConversionVisitor) Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 4 with CommandBuilder

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());
}
Also used : SQLConversionVisitor(org.teiid.translator.jdbc.SQLConversionVisitor) Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 5 with CommandBuilder

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());
}
Also used : SQLConversionVisitor(org.teiid.translator.jdbc.SQLConversionVisitor) Command(org.teiid.language.Command) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Aggregations

CommandBuilder (org.teiid.cdk.CommandBuilder)34 Test (org.junit.Test)31 Command (org.teiid.language.Command)25 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)9 ExecutionContext (org.teiid.translator.ExecutionContext)8 RuntimeMetadataImpl (org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl)6 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)6 Properties (java.util.Properties)5 DataSource (javax.activation.DataSource)5 Call (org.teiid.language.Call)5 MetadataFactory (org.teiid.metadata.MetadataFactory)5 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)5 WSConnection (org.teiid.translator.WSConnection)5 Connection (java.sql.Connection)4 Select (org.teiid.language.Select)4 StAXSource (javax.xml.transform.stax.StAXSource)3 Procedure (org.teiid.metadata.Procedure)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2