Search in sources :

Example 26 with Command

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

Example 27 with Command

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

Example 28 with Command

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

Example 29 with Command

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());
}
Also used : Command(org.teiid.language.Command)

Example 30 with Command

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();
    }
}
Also used : ResultSetExecution(org.teiid.translator.ResultSetExecution) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) ArrayList(java.util.ArrayList)

Aggregations

Command (org.teiid.language.Command)136 Test (org.junit.Test)99 ExecutionContext (org.teiid.translator.ExecutionContext)62 TranslationUtility (org.teiid.cdk.api.TranslationUtility)52 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)40 CommandBuilder (org.teiid.cdk.CommandBuilder)25 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)20 ResultSetExecution (org.teiid.translator.ResultSetExecution)18 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)17 UpdateExecution (org.teiid.translator.UpdateExecution)16 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 List (java.util.List)11 Connection (java.sql.Connection)10 LdapContext (javax.naming.ldap.LdapContext)9 Range (org.apache.accumulo.core.data.Range)9 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 MetadataFactory (org.teiid.metadata.MetadataFactory)8 ArrayList (java.util.ArrayList)7 FunctionTree (org.teiid.query.function.FunctionTree)7 UDFSource (org.teiid.query.function.UDFSource)7