use of org.teiid.language.Expression 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();
}
use of org.teiid.language.Expression in project teiid by teiid.
the class CouchbaseExecutionFactory method start.
@Override
public void start() throws TranslatorException {
super.start();
registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new SubstringFunctionModifier());
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CEILING, new AliasModifier("CEIL"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LOG, new AliasModifier("LN"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LOG10, new AliasModifier("LOG"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.RAND, new AliasModifier("RANDOM"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LCASE, new AliasModifier("LOWER"));
// $NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.UCASE, new AliasModifier("UPPER"));
registerFunctionModifier(SourceSystemFunctions.CONVERT, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
Expression param = function.getParameters().get(0);
int targetCode = getCode(function.getType());
if (targetCode == BYTE || targetCode == SHORT || targetCode == INTEGER || targetCode == LONG || targetCode == FLOAT || targetCode == DOUBLE || targetCode == BIGINTEGER || targetCode == BIGDECIMAL) {
if ((Number.class.isAssignableFrom(param.getType()))) {
return Arrays.asList(param);
}
// $NON-NLS-1$
return Arrays.asList("TONUMBER" + Tokens.LPAREN, param, Tokens.RPAREN);
} else if (targetCode == STRING || targetCode == CHAR) {
// $NON-NLS-1$
return Arrays.asList("TOSTRING" + Tokens.LPAREN, param, Tokens.RPAREN);
} else if (targetCode == BOOLEAN) {
// $NON-NLS-1$
return Arrays.asList("TOBOOLEAN" + Tokens.LPAREN, param, Tokens.RPAREN);
} else {
return Arrays.asList(param);
}
}
});
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "CONTAINS", TypeFacility.RUNTIME_NAMES.BOOLEAN, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "TITLE", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "LTRIM", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "TRIM", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "RTRIM", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "POSITION", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "CLOCK_MILLIS", TypeFacility.RUNTIME_NAMES.DOUBLE);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "CLOCK_STR", TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "CLOCK_STR", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "DATE_ADD_MILLIS", TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "DATE_ADD_STR", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "DATE_DIFF_MILLIS", TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "DATE_DIFF_STR", TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "DATE_PART_MILLIS", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.LONG, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "DATE_PART_STR", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "NOW_MILLIS", TypeFacility.RUNTIME_NAMES.DOUBLE);
// $NON-NLS-1$
addPushDownFunction(COUCHBASE, "NOW_STR", TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING);
}
use of org.teiid.language.Expression in project teiid by teiid.
the class SpreadsheetInsertVisitor method visit.
public void visit(Insert obj) {
worksheetTitle = obj.getTable().getName();
if (obj.getTable().getMetadataObject().getNameInSource() != null) {
worksheetTitle = obj.getTable().getMetadataObject().getNameInSource();
}
worksheetKey = info.getWorksheetByName(worksheetTitle).getId();
ExpressionValueSource evs = (ExpressionValueSource) obj.getValueSource();
for (int i = 0; i < evs.getValues().size(); i++) {
Expression e = evs.getValues().get(i);
if (!(e instanceof Literal)) {
throw new SpreadsheetOperationException("Only literals are allowed in the values section");
}
Literal l = (Literal) e;
if (l.getValue() == null) {
continue;
}
ColumnReference columnReference = obj.getColumns().get(i);
columnNameValuePair.put(columnReference.getMetadataObject().getSourceName(), l.getValue());
}
}
use of org.teiid.language.Expression in project teiid by teiid.
the class TestSQLtoSpreadsheetQuery method helpTestExpression.
private void helpTestExpression(String expression, String expected) throws QueryParserException {
LanguageBridgeFactory lbf = new LanguageBridgeFactory(RealMetadataFactory.example1Cached());
Expression ex = lbf.translate(QueryParser.getQueryParser().parseExpression(expression));
SpreadsheetSQLVisitor spreadsheetVisitor = new SpreadsheetSQLVisitor(people);
spreadsheetVisitor.translateSQL(ex);
assertEquals(expected, spreadsheetVisitor.getTranslatedSQL());
}
use of org.teiid.language.Expression in project teiid by teiid.
the class InfinispanUpdateVisitor method buildInsertPayload.
private InfinispanDocument buildInsertPayload(Insert obj, List<Expression> values) {
InfinispanDocument targetDocument = null;
try {
// table that insert issued for
Table table = obj.getTable().getMetadataObject();
Column pkColumn = getPrimaryKey();
// create the top table parent document, where insert is actually being done at
targetDocument = buildTargetDocument(table, true);
// build the payload object from insert
int elementCount = obj.getColumns().size();
for (int i = 0; i < elementCount; i++) {
ColumnReference columnReference = obj.getColumns().get(i);
Column column = columnReference.getMetadataObject();
Object value = null;
if (values.get(i) instanceof Expression) {
Expression expr = values.get(i);
value = resolveExpressionValue(expr);
} else {
value = values.get(i);
}
updateDocument(targetDocument, column, value);
if (column.equals(pkColumn) || pkColumn.equals(normalizePseudoColumn(column))) {
targetDocument.setIdentifier(value);
}
}
if (targetDocument.getIdentifier() == null) {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25004, getParentTable().getName())));
}
} catch (NumberFormatException e) {
this.exceptions.add(new TranslatorException(e));
} catch (TranslatorException e) {
this.exceptions.add(new TranslatorException(e));
}
return targetDocument;
}
Aggregations