Search in sources :

Example 61 with Constant

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

the class TestResolver method testExecNamedParamsReversed.

/**
 * try entering params out of order
 */
@Test
public void testExecNamedParamsReversed() {
    // $NON-NLS-1$
    Object[] expectedParameterExpressions = new Object[] { new Constant("xyz"), new Constant(new Integer(5)) };
    // $NON-NLS-1$
    helpResolveExec("EXEC pm1.sq3(in2 = 5, \"in\" = 'xyz')", 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 62 with Constant

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

the class TestResolver method testStringConversion1.

@Test
public void testStringConversion1() {
    // Expected left expression
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("pm3.g1.e2");
    e1.setType(DataTypeManager.DefaultDataClasses.DATE);
    // Expected right expression
    Class srcType = DataTypeManager.DefaultDataClasses.STRING;
    String tgtTypeName = DataTypeManager.DefaultDataTypes.DATE;
    // $NON-NLS-1$
    Expression expression = new Constant("2003-02-27");
    FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
    FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
    Function conversion = new Function(fd.getName(), new Expression[] { expression, new Constant(tgtTypeName) });
    conversion.setType(DataTypeManager.getDataTypeClass(tgtTypeName));
    conversion.setFunctionDescriptor(fd);
    conversion.makeImplicit();
    // Expected criteria
    CompareCriteria expected = new CompareCriteria();
    expected.setLeftExpression(e1);
    expected.setOperator(CompareCriteria.EQ);
    expected.setRightExpression(conversion);
    // Resolve the query and check against expected objects
    // $NON-NLS-1$
    CompareCriteria actual = (CompareCriteria) helpResolveCriteria("pm3.g1.e2='2003-02-27'");
    // $NON-NLS-1$
    assertEquals("Did not match expected criteria", expected, actual);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Test(org.junit.Test)

Example 63 with Constant

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

the class TestResolver method testExecNamedParams.

@Test
public void testExecNamedParams() {
    // $NON-NLS-1$
    Object[] expectedParameterExpressions = new Object[] { new Constant("xyz"), new Constant(new Integer(5)) };
    // $NON-NLS-1$
    helpResolveExec("EXEC pm1.sq3(\"in\" = 'xyz', in2 = 5)", 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 64 with Constant

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

the class TestResolver method testExecNamedParamsOmitRequiredParamWithDefaultValue.

/**
 * test omitting a required parameter that has a default value
 */
@Test
public void testExecNamedParamsOmitRequiredParamWithDefaultValue() {
    // $NON-NLS-1$ //$NON-NLS-2$
    Object[] expectedParameterExpressions = new Object[] { new Constant("xyz"), new Constant(new Integer(666)), new Constant("YYZ") };
    // $NON-NLS-1$
    StoredProcedure sp = helpResolveExec("EXEC pm1.sq3b(\"in\" = 'xyz', in2 = 666)", expectedParameterExpressions);
    assertEquals("EXEC pm1.sq3b(\"in\" => 'xyz', in2 => 666)", sp.toString());
}
Also used : BigInteger(java.math.BigInteger) Constant(org.teiid.query.sql.symbol.Constant) LanguageObject(org.teiid.query.sql.LanguageObject) Test(org.junit.Test)

Example 65 with Constant

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

the class TestResolver method testExecNamedParamsOptionalParamWithDefaultsCaseInsensitive.

@Test
public void testExecNamedParamsOptionalParamWithDefaultsCaseInsensitive() {
    Object[] expectedParameterExpressions = helpGetStoredProcDefaultValues();
    // override the default value for the first parameter
    // $NON-NLS-1$
    expectedParameterExpressions[0] = new Constant("xyz");
    // $NON-NLS-1$
    helpResolveExec("EXEC pm1.sqDefaults(iNsTrInG = 'xyz')", expectedParameterExpressions);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) LanguageObject(org.teiid.query.sql.LanguageObject) 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