Search in sources :

Example 6 with Expression

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

Example 7 with Expression

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

the class ODataUpdateVisitor method visit.

@Override
public void visit(Insert obj) {
    // $NON-NLS-1$
    this.method = "POST";
    this.entity = obj.getTable().getMetadataObject();
    this.uri = this.entity.getName();
    final List<OProperty<?>> props = new ArrayList<OProperty<?>>();
    int elementCount = obj.getColumns().size();
    for (int i = 0; i < elementCount; i++) {
        Column column = obj.getColumns().get(i).getMetadataObject();
        List<Expression> values = ((ExpressionValueSource) obj.getValueSource()).getValues();
        OProperty<?> property = readProperty(column, values.get(i));
        props.add(property);
    }
    this.payload = props;
}
Also used : OProperty(org.odata4j.core.OProperty) Column(org.teiid.metadata.Column) Expression(org.teiid.language.Expression) ArrayList(java.util.ArrayList) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 8 with Expression

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

the class InfinispanUpdateVisitor method visit.

@Override
public void visit(Insert obj) {
    this.operationType = OperationType.INSERT;
    if (obj.isUpsert()) {
        this.operationType = OperationType.UPSERT;
    }
    visitNode(obj.getTable());
    Column pkColumn = getPrimaryKey();
    if (pkColumn == null) {
        this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25013, getParentTable().getName())));
        return;
    }
    if (obj.getParameterValues() == null) {
        List<Expression> values = ((ExpressionValueSource) obj.getValueSource()).getValues();
        this.insertPayload = buildInsertPayload(obj, values);
        if (this.insertPayload != null) {
            this.identity = this.insertPayload.getIdentifier();
        }
    }
}
Also used : Column(org.teiid.metadata.Column) Expression(org.teiid.language.Expression) TranslatorException(org.teiid.translator.TranslatorException) ExpressionValueSource(org.teiid.language.ExpressionValueSource)

Example 9 with Expression

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

the class HanaSpatialFunctionModifier method translate.

/**
 * Most geospatial functions in HANA are called from the geometry object or an equivalent expression.
 * For example, <geometry-expression>.ST_SRID() or <geometry-expression>.ST_Relate(<geo2>). This method
 * will take the argument(s) to the Teiid spatial function and move the first argument to precede
 * the function name.
 */
public List<?> translate(Function function) {
    List<Expression> params = function.getParameters();
    List<Object> objs = new ArrayList<Object>();
    Expression exp1 = params.get(0);
    objs.add(exp1 + "." + function.getName());
    // $NON-NLS-1$
    objs.add("(");
    if (params.size() > 1) {
        objs.add(params.get(1));
    }
    // $NON-NLS-1$
    objs.add(")");
    return objs;
}
Also used : Expression(org.teiid.language.Expression) ArrayList(java.util.ArrayList)

Example 10 with Expression

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

the class AddDiffModifier method translate.

@Override
public List<?> translate(Function function) {
    if (add) {
        // $NON-NLS-1$
        function.setName("dateadd");
    } else {
        // $NON-NLS-1$
        function.setName("datediff");
    }
    Literal intervalType = (Literal) function.getParameters().get(0);
    String interval = ((String) intervalType.getValue()).toUpperCase();
    String newInterval = INTERVAL_MAP.get(interval);
    if (newInterval != null) {
        intervalType.setValue(newInterval);
        return null;
    }
    if (supportsQuarter && interval.equals(NonReserved.SQL_TSI_QUARTER)) {
        // $NON-NLS-1$
        intervalType.setValue("QUARTER");
        return null;
    }
    if (add) {
        if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
            // $NON-NLS-1$
            intervalType.setValue("MILLISECOND");
            Expression[] args = new Expression[] { function.getParameters().get(1), factory.createLiteral(1000000, TypeFacility.RUNTIME_TYPES.INTEGER) };
            // $NON-NLS-1$
            function.getParameters().set(1, factory.createFunction("/", args, TypeFacility.RUNTIME_TYPES.INTEGER));
        } else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
            intervalType.setValue(ExtractFunctionModifier.DAY);
            Expression[] args = new Expression[] { function.getParameters().get(1), factory.createLiteral(91, TypeFacility.RUNTIME_TYPES.INTEGER) };
            // $NON-NLS-1$
            function.getParameters().set(1, factory.createFunction("*", args, TypeFacility.RUNTIME_TYPES.INTEGER));
        } else {
            intervalType.setValue(ExtractFunctionModifier.DAY);
            Expression[] args = new Expression[] { function.getParameters().get(1), factory.createLiteral(7, TypeFacility.RUNTIME_TYPES.INTEGER) };
            // $NON-NLS-1$
            function.getParameters().set(1, factory.createFunction("*", args, TypeFacility.RUNTIME_TYPES.INTEGER));
        }
        return null;
    }
    if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
        // $NON-NLS-1$
        intervalType.setValue("MILLISECOND");
        // $NON-NLS-1$
        return Arrays.asList(function, " * 1000000");
    } else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
        intervalType.setValue(ExtractFunctionModifier.DAY);
        // $NON-NLS-1$
        return Arrays.asList(function, " / 91");
    }
    intervalType.setValue(ExtractFunctionModifier.DAY);
    // $NON-NLS-1$
    return Arrays.asList(function, " / 7");
}
Also used : Expression(org.teiid.language.Expression) Literal(org.teiid.language.Literal)

Aggregations

Expression (org.teiid.language.Expression)61 ArrayList (java.util.ArrayList)18 ExpressionValueSource (org.teiid.language.ExpressionValueSource)18 Literal (org.teiid.language.Literal)17 TranslatorException (org.teiid.translator.TranslatorException)16 ColumnReference (org.teiid.language.ColumnReference)14 Function (org.teiid.language.Function)13 Column (org.teiid.metadata.Column)12 Insert (org.teiid.language.Insert)11 List (java.util.List)10 Table (org.teiid.metadata.Table)9 BigInteger (java.math.BigInteger)7 Test (org.junit.Test)7 Parameter (org.teiid.language.Parameter)7 Iterator (java.util.Iterator)5 Comparison (org.teiid.language.Comparison)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 FakeExecutionContextImpl (org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl)4 NamedTable (org.teiid.language.NamedTable)4