Search in sources :

Example 76 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestProcedureResolving method testOptionalParams.

@Test
public void testOptionalParams() throws Exception {
    String ddl = "create foreign procedure proc (x integer, y string);\n";
    TransformationMetadata tm = createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call proc (1)";
    StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals(new Constant(null, DataTypeManager.DefaultDataClasses.STRING), sp.getParameter(2).getExpression());
    // $NON-NLS-1$
    sql = "call proc (1, 'a')";
    sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals(new Constant("a", DataTypeManager.DefaultDataClasses.STRING), sp.getParameter(2).getExpression());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 77 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestProcedureResolving method testVarArgs2.

@Test
public void testVarArgs2() throws Exception {
    String ddl = "create foreign procedure proc (VARIADIC z object) 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.OBJECT, new ArrayList<Expression>(0)), sp.getParameter(1).getExpression());
    // $NON-NLS-1$
    sql = "call proc (1, (2, 3))";
    sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1, (2, 3))", sp.toString());
    ArrayList<Expression> expressions = new ArrayList<Expression>();
    expressions.add(new Constant(1));
    expressions.add(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))));
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.OBJECT, expressions), sp.getParameter(1).getExpression());
}
Also used : Array(org.teiid.query.sql.symbol.Array) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 78 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestResolver method testCriteria1.

@Test
public void testCriteria1() {
    CompareCriteria expected = new CompareCriteria();
    // $NON-NLS-1$
    ElementSymbol es = new ElementSymbol("pm1.g1.e1");
    // $NON-NLS-1$
    GroupSymbol gs = new GroupSymbol("pm1.g1");
    es.setGroupSymbol(gs);
    expected.setLeftExpression(es);
    expected.setOperator(CompareCriteria.EQ);
    // $NON-NLS-1$
    expected.setRightExpression(new Constant("abc"));
    // $NON-NLS-1$
    Criteria actual = helpResolveCriteria("pm1.g1.e1 = 'abc'");
    // $NON-NLS-1$
    assertEquals("Did not match expected criteria", expected, actual);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) Test(org.junit.Test)

Example 79 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestResolver method testExecNamedParamsOptionalParamWithDefaults2.

/**
 * try just a few named parameters, in no particular order
 */
@Test
public void testExecNamedParamsOptionalParamWithDefaults2() {
    Object[] expectedParameterExpressions = helpGetStoredProcDefaultValues();
    // override the proper default values in expected results
    expectedParameterExpressions[3] = new Constant(Boolean.FALSE);
    expectedParameterExpressions[9] = new Constant(new Integer(666));
    // $NON-NLS-1$
    helpResolveExec("EXEC pm1.sqDefaults(ininteger = 666, inboolean={b'false'})", expectedParameterExpressions);
}
Also used : BigInteger(java.math.BigInteger) Constant(org.teiid.query.sql.symbol.Constant) LanguageObject(org.teiid.query.sql.LanguageObject) Test(org.junit.Test)

Example 80 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestResolver method testStoredQueryParamOrdering_8211.

/**
 * per defect 8211 - Input params do not have to be numbered sequentially in metadata.  For example,
 * the first input param can be #1 and the second input param can be #3.  (This occurs in
 * QueryBuilder's metadata where the return param happens to be created in between the two
 * input params and is numbered #2, but is not loaded into QueryBuilder's runtime env).
 * When the user's query is parsed and resolved, the placeholder
 * input params are numbered #1 and #2.  This test tests that this disparity in ordering should not
 * be a problem as long as RELATIVE ordering is in synch.
 */
@Test
public void testStoredQueryParamOrdering_8211() {
    // $NON-NLS-1$
    StoredProcedure proc = (StoredProcedure) helpResolve("EXEC pm1.sq3a('abc', 123)");
    // Check number of resolved parameters
    Map<Integer, SPParameter> params = proc.getMapOfParameters();
    // $NON-NLS-1$
    assertEquals("Did not get expected parameter count", 3, params.size());
    // Check resolved parameters
    SPParameter param1 = params.get(1);
    // $NON-NLS-1$ //$NON-NLS-2$
    helpCheckParameter(param1, ParameterInfo.IN, 1, "pm1.sq3a.in", DataTypeManager.DefaultDataClasses.STRING, new Constant("abc"));
    SPParameter param2 = params.get(2);
    // $NON-NLS-1$
    helpCheckParameter(param2, ParameterInfo.IN, 2, "pm1.sq3a.in2", DataTypeManager.DefaultDataClasses.INTEGER, new Constant(new Integer(123)));
}
Also used : BigInteger(java.math.BigInteger) Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Aggregations

Constant (org.teiid.query.sql.symbol.Constant)203 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)94 Test (org.junit.Test)88 ArrayList (java.util.ArrayList)61 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)48 List (java.util.List)38 Expression (org.teiid.query.sql.symbol.Expression)38 Function (org.teiid.query.sql.symbol.Function)31 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)25 Query (org.teiid.query.sql.lang.Query)22 Select (org.teiid.query.sql.lang.Select)15 Reference (org.teiid.query.sql.symbol.Reference)14 From (org.teiid.query.sql.lang.From)12 HashMap (java.util.HashMap)11 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)11 Criteria (org.teiid.query.sql.lang.Criteria)11 SetQuery (org.teiid.query.sql.lang.SetQuery)11 LinkedList (java.util.LinkedList)10 Limit (org.teiid.query.sql.lang.Limit)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)9