Search in sources :

Example 1 with LanguageBridgeFactory

use of org.teiid.dqp.internal.datamgr.LanguageBridgeFactory in project teiid by teiid.

the class TestProcedureResolving method testVarArgs.

@Test
public void testVarArgs() throws Exception {
    String ddl = "create foreign procedure proc (x integer, VARIADIC z integer) returns (x string);\n";
    TransformationMetadata tm = createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call proc (1, 2, 3)";
    StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1, 2, 3)", sp.toString());
    assertEquals(new Constant(1), sp.getParameter(1).getExpression());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
    assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
    // $NON-NLS-1$
    sql = "call proc (1)";
    sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1)", sp.toString());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(2).getExpression());
    sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm);
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm);
    Call call = (Call) lbf.translate(sp);
    assertEquals("EXEC proc(1)", call.toString());
    // $NON-NLS-1$
    sql = "call proc (1, (2, 3))";
    sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1, (2, 3))", sp.toString());
    assertEquals(new Constant(1), sp.getParameter(1).getExpression());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
    assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
}
Also used : Array(org.teiid.query.sql.symbol.Array) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) Test(org.junit.Test)

Example 2 with LanguageBridgeFactory

use of org.teiid.dqp.internal.datamgr.LanguageBridgeFactory in project teiid by teiid.

the class TestAliasGenerator method testStripAliases1.

@Test
public void testStripAliases1() throws Exception {
    // $NON-NLS-1$
    String sql = "select intkey as a, stringkey as b from BQT1.SmallA ORDER BY a, b";
    // $NON-NLS-1$
    String expected = "SELECT BQT1.SmallA.IntKey, BQT1.SmallA.StringKey FROM BQT1.SmallA ORDER BY BQT1.SmallA.IntKey, BQT1.SmallA.StringKey";
    Command command = helpTest(sql, expected, false, true, RealMetadataFactory.exampleBQTCached());
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.exampleBQTCached());
    org.teiid.language.Command c = lbf.translate(command);
    assertEquals("SELECT SmallA.IntKey, SmallA.StringKey FROM SmallA ORDER BY SmallA.IntKey, SmallA.StringKey", c.toString());
}
Also used : Command(org.teiid.query.sql.lang.Command) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) Test(org.junit.Test)

Example 3 with LanguageBridgeFactory

use of org.teiid.dqp.internal.datamgr.LanguageBridgeFactory in project teiid by teiid.

the class TestSQLtoSpreadsheetQuery method helpTestExpression.

private void helpTestExpression(String expression, String expected) throws QueryParserException {
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.example1Cached());
    Expression ex = lbf.translate(QueryParser.getQueryParser().parseExpression(expression));
    SpreadsheetSQLVisitor spreadsheetVisitor = new SpreadsheetSQLVisitor(people);
    spreadsheetVisitor.translateSQL(ex);
    assertEquals(expected, spreadsheetVisitor.getTranslatedSQL());
}
Also used : Expression(org.teiid.language.Expression) SpreadsheetSQLVisitor(org.teiid.translator.google.visitor.SpreadsheetSQLVisitor) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory)

Example 4 with LanguageBridgeFactory

use of org.teiid.dqp.internal.datamgr.LanguageBridgeFactory in project teiid by teiid.

the class TestAliasGenerator method testInlineViewOrderBy.

@Test
public void testInlineViewOrderBy() throws Exception {
    // $NON-NLS-1$
    String sql = "select intnum from (select intnum from bqt1.smallb) b order by b.intnum";
    // $NON-NLS-1$
    String expected = "SELECT v_0.c_0 FROM (SELECT g_0.IntNum AS c_0 FROM BQT1.SmallB AS g_0) AS v_0 ORDER BY c_0";
    Command command = helpTest(sql, expected, true, false, RealMetadataFactory.exampleBQTCached());
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.exampleBQTCached());
    org.teiid.language.Command c = lbf.translate(command);
    assertEquals("SELECT v_0.c_0 FROM (SELECT g_0.IntNum AS c_0 FROM SmallB AS g_0) AS v_0 ORDER BY v_0.c_0", c.toString());
}
Also used : Command(org.teiid.query.sql.lang.Command) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) Test(org.junit.Test)

Example 5 with LanguageBridgeFactory

use of org.teiid.dqp.internal.datamgr.LanguageBridgeFactory in project teiid by teiid.

the class TestProcedureResolving method testVarArgs1.

@Test
public void testVarArgs1() throws Exception {
    String ddl = "create foreign procedure proc (VARIADIC z integer) returns (x string);\n";
    TransformationMetadata tm = createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call proc ()";
    StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc()", sp.toString());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(1).getExpression());
    sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm);
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm);
    Call call = (Call) lbf.translate(sp);
    assertEquals("EXEC proc()", call.toString());
    // we pass to the translator level flattened, so no argument
    assertEquals(0, call.getArguments().size());
}
Also used : Array(org.teiid.query.sql.symbol.Array) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) Test(org.junit.Test)

Aggregations

LanguageBridgeFactory (org.teiid.dqp.internal.datamgr.LanguageBridgeFactory)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 Call (org.teiid.language.Call)2 Evaluator (org.teiid.query.eval.Evaluator)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 Command (org.teiid.query.sql.lang.Command)2 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)2 Array (org.teiid.query.sql.symbol.Array)2 Expression (org.teiid.language.Expression)1 Constant (org.teiid.query.sql.symbol.Constant)1 SpreadsheetSQLVisitor (org.teiid.translator.google.visitor.SpreadsheetSQLVisitor)1