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);
}
}
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;
}
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();
}
}
}
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;
}
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");
}
Aggregations