Search in sources :

Example 6 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class TestCompareCriteriaImpl method testGetLeftExpression.

public void testGetLeftExpression() throws Exception {
    Comparison impl = example(AbstractCompareCriteria.GE, 200, 100);
    assertNotNull(impl.getLeftExpression());
    assertTrue(impl.getLeftExpression() instanceof Literal);
    assertEquals(new Integer(200), ((Literal) impl.getLeftExpression()).getValue());
}
Also used : Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal)

Example 7 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class TestInCriteriaImpl method testGetLeftExpression.

@Test
public void testGetLeftExpression() throws Exception {
    In inCriteria = example(false);
    assertNotNull(inCriteria.getLeftExpression());
    assertTrue(inCriteria.getLeftExpression() instanceof Literal);
    assertEquals(new Integer(300), ((Literal) inCriteria.getLeftExpression()).getValue());
}
Also used : In(org.teiid.language.In) Literal(org.teiid.language.Literal) Test(org.junit.Test)

Example 8 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class TestLikeCriteriaImpl method testGetRightExpression.

public void testGetRightExpression() throws Exception {
    // $NON-NLS-1$
    Like like = example("abc", '.', false);
    assertNotNull(like.getRightExpression());
    assertTrue(like.getRightExpression() instanceof Literal);
    // $NON-NLS-1$
    assertEquals("abc", ((Literal) like.getRightExpression()).getValue());
}
Also used : Like(org.teiid.language.Like) Literal(org.teiid.language.Literal)

Example 9 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class TestMongoDBQueryExecution method testGeoFunctionInWhereWithGeometry.

@Test
public void testGeoFunctionInWhereWithGeometry() throws Exception {
    Table table = this.utility.createRuntimeMetadata().getTable("northwind.Categories");
    NamedTable namedTable = new NamedTable("Categories", "g0", table);
    ColumnReference colRef = new ColumnReference(namedTable, "CategoryName", table.getColumnByName("CategoryName"), String.class);
    DerivedColumn col = new DerivedColumn("CategoryName", colRef);
    Select select = new Select();
    select.setDerivedColumns(Arrays.asList(col));
    List<TableReference> tables = new ArrayList<TableReference>();
    tables.add(namedTable);
    select.setFrom(tables);
    final GeometryType geo = GeometryUtils.geometryFromClob(new ClobType(new ClobImpl("POLYGON ((1.0 2.0,3.0 4.0,5.0 6.0,1.0 2.0))")));
    Function function = new // $NON-NLS-1$
    Function(// $NON-NLS-1$
    "mongo.geoWithin", // $NON-NLS-1$
    Arrays.asList(colRef, new Literal(geo, GeometryType.class)), // $NON-NLS-2$
    Boolean.class);
    function.setMetadataObject(getFunctionMethod("mongo.geoWithin"));
    Comparison c = new Comparison(function, new Literal(true, Boolean.class), Comparison.Operator.EQ);
    select.setWhere(c);
    DBCollection dbCollection = helpExecute(select, new String[] { "Categories" }, 2);
    BasicDBObjectBuilder builder = new BasicDBObjectBuilder();
    builder.push("CategoryName");
    // $NON-NLS-1$
    builder.push("$geoWithin");
    // $NON-NLS-1$
    builder.add("$geometry", "{\"type\":\"Polygon\",\"coordinates\":[[[1.0,2.0],[3.0,4.0],[5.0,6.0],[1.0,2.0]]]}");
    BasicDBObject result = new BasicDBObject();
    result.append("CategoryName", "$CategoryName");
    List<DBObject> pipeline = buildArray(new BasicDBObject("$match", builder.get()), new BasicDBObject("$project", result));
    Mockito.verify(dbCollection).aggregate(Mockito.eq(pipeline), Mockito.any(AggregationOptions.class));
}
Also used : NamedTable(org.teiid.language.NamedTable) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) ArrayList(java.util.ArrayList) ClobType(org.teiid.core.types.ClobType) GeometryType(org.teiid.core.types.GeometryType) Function(org.teiid.language.Function) TableReference(org.teiid.language.TableReference) Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal) Select(org.teiid.language.Select) DerivedColumn(org.teiid.language.DerivedColumn) ClobImpl(org.teiid.core.types.ClobImpl) ColumnReference(org.teiid.language.ColumnReference) Test(org.junit.Test)

Example 10 with Literal

use of org.teiid.language.Literal in project teiid by teiid.

the class InsertExecutionImpl method buildBulkRowPayload.

protected List<com.sforce.async.SObject> buildBulkRowPayload(Insert insert, Iterator<? extends List<?>> it, int rowCount) throws TranslatorException {
    List<com.sforce.async.SObject> rows = new ArrayList<com.sforce.async.SObject>();
    List<ColumnReference> columns = insert.getColumns();
    int boundCount = 0;
    List<Expression> literalValues = ((ExpressionValueSource) insert.getValueSource()).getValues();
    while (it.hasNext()) {
        if (boundCount >= rowCount) {
            break;
        }
        boundCount++;
        List<?> values = it.next();
        com.sforce.async.SObject sobj = new com.sforce.async.SObject();
        for (int i = 0; i < columns.size(); i++) {
            Expression ex = literalValues.get(i);
            ColumnReference element = columns.get(i);
            Column column = element.getMetadataObject();
            Class<?> type = ex.getType();
            Object value = null;
            if (ex instanceof Parameter) {
                value = values.get(((Parameter) ex).getValueIndex());
            } else if (!(ex instanceof Literal)) {
                throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13007));
            } else {
                value = ((Literal) ex).getValue();
            }
            sobj.setField(column.getSourceName(), getStringValue(value, type));
        }
        rows.add(sobj);
    }
    return rows;
}
Also used : ArrayList(java.util.ArrayList) Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) SObject(com.sforce.async.SObject) Parameter(org.teiid.language.Parameter) SObject(com.sforce.async.SObject) TranslatorException(org.teiid.translator.TranslatorException) SObject(com.sforce.async.SObject) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Aggregations

Literal (org.teiid.language.Literal)82 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)18 Expression (org.teiid.language.Expression)17 TranslatorException (org.teiid.translator.TranslatorException)16 Function (org.teiid.language.Function)15 Argument (org.teiid.language.Argument)12 ColumnReference (org.teiid.language.ColumnReference)10 Column (org.teiid.metadata.Column)10 Comparison (org.teiid.language.Comparison)9 ExpressionValueSource (org.teiid.language.ExpressionValueSource)7 List (java.util.List)5 Call (org.teiid.language.Call)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 Timestamp (java.sql.Timestamp)3 Array (org.teiid.language.Array)3 Command (org.teiid.language.Command)3 Insert (org.teiid.language.Insert)3