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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations