Search in sources :

Example 1 with ColumnReference

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

the class AccumuloUpdateExecution method performInsert.

private void performInsert(Insert insert) throws TranslatorException, TableNotFoundException, MutationsRejectedException {
    Table table = insert.getTable().getMetadataObject();
    this.updateCount = 0;
    Connector connector = this.connection.getInstance();
    BatchWriter writer = createBatchWriter(table, connector);
    List<ColumnReference> columns = insert.getColumns();
    if (insert.getParameterValues() == null) {
        List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
        writeMutation(writer, columns, values);
        this.updateCount++;
    } else {
        int batchSize = this.executionContext.getBatchSize();
        // bulk insert; should help
        Iterator<? extends List<Expression>> args = (Iterator<? extends List<Expression>>) insert.getParameterValues();
        while (args.hasNext()) {
            List<Expression> values = args.next();
            writeMutation(writer, columns, values);
            this.updateCount++;
            if ((this.updateCount % batchSize) == 0) {
                writer.close();
                writer = createBatchWriter(table, connector);
            }
        }
    }
    // write the mutation
    writer.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Table(org.teiid.metadata.Table) Expression(org.teiid.language.Expression) Iterator(java.util.Iterator) List(java.util.List) BatchWriter(org.apache.accumulo.core.client.BatchWriter) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 2 with ColumnReference

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

the class TestSetQueryImpl method example3.

public static SetQuery example3() throws Exception {
    SetQuery union = example2();
    List<SortSpecification> items = new ArrayList<SortSpecification>();
    // $NON-NLS-1$
    items.add(new SortSpecification(Ordering.ASC, new ColumnReference(null, "nugent", null, DataTypeManager.DefaultDataClasses.STRING)));
    OrderBy orderBy = new OrderBy(items);
    union.setOrderBy(orderBy);
    return union;
}
Also used : OrderBy(org.teiid.language.OrderBy) SetQuery(org.teiid.language.SetQuery) SortSpecification(org.teiid.language.SortSpecification) ArrayList(java.util.ArrayList) ColumnReference(org.teiid.language.ColumnReference)

Example 3 with ColumnReference

use of org.teiid.language.ColumnReference 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 4 with ColumnReference

use of org.teiid.language.ColumnReference 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)

Example 5 with ColumnReference

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

the class InsertExecutionImpl method buildSingleRowInsertPayload.

private void buildSingleRowInsertPayload(Insert insert, DataPayload data) throws TranslatorException {
    List<ColumnReference> columns = insert.getColumns();
    List<Expression> values = ((ExpressionValueSource) insert.getValueSource()).getValues();
    if (columns.size() != values.size()) {
        throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13006));
    }
    for (int i = 0; i < columns.size(); i++) {
        Column column = columns.get(i).getMetadataObject();
        Object value = values.get(i);
        if (!(value instanceof Literal)) {
            throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13007));
        }
        Literal literalValue = (Literal) values.get(i);
        Object val = literalValue.getValue();
        if (val instanceof Timestamp) {
            Calendar cal = Calendar.getInstance();
            cal.setTime((Timestamp) val);
            val = cal;
        }
        data.addField(column.getSourceName(), val);
    }
}
Also used : Expression(org.teiid.language.Expression) Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) Calendar(java.util.Calendar) TranslatorException(org.teiid.translator.TranslatorException) SObject(com.sforce.async.SObject) Timestamp(java.sql.Timestamp) ColumnReference(org.teiid.language.ColumnReference) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Aggregations

ColumnReference (org.teiid.language.ColumnReference)35 Expression (org.teiid.language.Expression)14 NamedTable (org.teiid.language.NamedTable)13 Column (org.teiid.metadata.Column)12 ArrayList (java.util.ArrayList)11 TranslatorException (org.teiid.translator.TranslatorException)11 ExpressionValueSource (org.teiid.language.ExpressionValueSource)10 Literal (org.teiid.language.Literal)10 Table (org.teiid.metadata.Table)10 DerivedColumn (org.teiid.language.DerivedColumn)8 Test (org.junit.Test)7 Select (org.teiid.language.Select)6 Insert (org.teiid.language.Insert)5 List (java.util.List)4 Iterator (java.util.Iterator)3 Function (org.teiid.language.Function)3 Parameter (org.teiid.language.Parameter)3 SetQuery (org.teiid.language.SetQuery)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)3