Search in sources :

Example 71 with Literal

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

the class UpdateExecutionImpl method processIds.

@Override
protected int processIds(String[] ids, IQueryProvidingVisitor visitor) throws ResourceException {
    List<DataPayload> updateDataList = new ArrayList<DataPayload>();
    for (int i = 0; i < ids.length; i++) {
        DataPayload data = new DataPayload();
        for (SetClause clause : ((Update) command).getChanges()) {
            ColumnReference element = clause.getSymbol();
            Column column = element.getMetadataObject();
            String val = ((Literal) clause.getValue()).toString();
            data.addField(column.getSourceName(), Util.stripQutes(val));
        }
        data.setType(visitor.getTableName());
        data.setID(ids[i]);
        updateDataList.add(data);
    }
    return getConnection().update(updateDataList);
}
Also used : Column(org.teiid.metadata.Column) Literal(org.teiid.language.Literal) ArrayList(java.util.ArrayList) Update(org.teiid.language.Update) SetClause(org.teiid.language.SetClause) ColumnReference(org.teiid.language.ColumnReference)

Example 72 with Literal

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

the class TickerCollectorVisitor method addTickerFromExpression.

private void addTickerFromExpression(Expression expr) {
    if (expr instanceof Literal) {
        Literal literal = (Literal) expr;
        if (literal.getType() == String.class) {
            String ticker = (String) literal.getValue();
            this.tickers.add(ticker.toUpperCase());
        } else {
            // $NON-NLS-1$
            this.exception = new TranslatorException(YahooPlugin.Util.getString("TickerCollectorVisitor.Unexpected_type", literal.getType().getName()));
        }
    } else {
        // $NON-NLS-1$
        this.exception = new TranslatorException(YahooPlugin.Util.getString("TickerCollectorVisitor.Unexpected_expression", expr));
    }
}
Also used : Literal(org.teiid.language.Literal) TranslatorException(org.teiid.translator.TranslatorException)

Example 73 with Literal

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

the class TestAggregateImpl method testGetExpression.

public void testGetExpression() throws Exception {
    // $NON-NLS-1$
    AggregateFunction agg = example("testName", NonReserved.COUNT, true, 42);
    assertNotNull(agg.getExpression());
    assertTrue(agg.getExpression() instanceof Literal);
    assertEquals(new Integer(42), ((Literal) agg.getExpression()).getValue());
}
Also used : AggregateFunction(org.teiid.language.AggregateFunction) Literal(org.teiid.language.Literal)

Example 74 with Literal

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

the class TestCompareCriteriaImpl method testGetRightExpression.

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

Example 75 with Literal

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

the class AccumuloUpdateExecution method performUpdate.

private void performUpdate(Update update) throws TranslatorException, TableNotFoundException, MutationsRejectedException {
    Table table = update.getTable().getMetadataObject();
    if (update.getParameterValues() != null) {
        throw new TranslatorException(AccumuloPlugin.Event.TEIID19005, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19005));
    }
    AccumuloQueryVisitor visitor = new AccumuloQueryVisitor(this.aef);
    visitor.visitNode(update.getWhere());
    if (!visitor.exceptions.isEmpty()) {
        throw visitor.exceptions.get(0);
    }
    Connector connector = this.connection.getInstance();
    BatchWriter writer = createBatchWriter(table, connector);
    Text prevRow = null;
    Iterator<Entry<Key, Value>> results = AccumuloQueryExecution.runQuery(this.aef, this.connection.getInstance(), this.connection.getAuthorizations(), visitor.getRanges(), table, visitor.scanIterators());
    while (results.hasNext()) {
        Key key = results.next().getKey();
        Text rowId = key.getRow();
        if (prevRow == null || !prevRow.equals(rowId)) {
            prevRow = rowId;
            Mutation mutation = new Mutation(rowId);
            List<SetClause> changes = update.getChanges();
            for (SetClause clause : changes) {
                Column column = clause.getSymbol().getMetadataObject();
                if (SQLStringVisitor.getRecordName(column).equalsIgnoreCase(AccumuloMetadataProcessor.ROWID)) {
                    throw new TranslatorException(AccumuloPlugin.Event.TEIID19002, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19002, table.getName()));
                }
                Expression value = clause.getValue();
                if (value instanceof Literal) {
                    buildMutation(mutation, column, ((Literal) value).getValue());
                } else {
                    throw new TranslatorException(AccumuloPlugin.Event.TEIID19001, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19001));
                }
            }
            writer.addMutation(mutation);
            this.updateCount++;
        }
    }
    writer.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Table(org.teiid.metadata.Table) Text(org.apache.hadoop.io.Text) Entry(java.util.Map.Entry) Column(org.teiid.metadata.Column) Expression(org.teiid.language.Expression) Literal(org.teiid.language.Literal) TranslatorException(org.teiid.translator.TranslatorException) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) SetClause(org.teiid.language.SetClause)

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