use of org.teiid.language.Literal in project teiid by teiid.
the class AccumuloUpdateExecution method getRowId.
private byte[] getRowId(List<ColumnReference> columns, List<Expression> values) throws TranslatorException {
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i).getMetadataObject();
String rowId = SQLStringVisitor.getRecordName(column);
if (rowId.equalsIgnoreCase(AccumuloMetadataProcessor.ROWID) || AccumuloQueryVisitor.isPartOfPrimaryKey(column)) {
Object value = values.get(i);
if (value instanceof Literal) {
return AccumuloDataTypeManager.serialize(((Literal) value).getValue());
}
throw new TranslatorException(AccumuloPlugin.Event.TEIID19006, AccumuloPlugin.Util.gs(AccumuloPlugin.Event.TEIID19006));
}
}
return null;
}
use of org.teiid.language.Literal in project teiid by teiid.
the class AccumuloUpdateExecution method writeMutation.
private void writeMutation(BatchWriter writer, List<ColumnReference> columns, List<Expression> values) throws MutationsRejectedException, TranslatorException {
byte[] rowId = getRowId(columns, values);
Mutation mutation = new Mutation(rowId);
for (int i = 0; i < columns.size(); i++) {
Column column = columns.get(i).getMetadataObject();
if (SQLStringVisitor.getRecordName(column).equalsIgnoreCase(AccumuloMetadataProcessor.ROWID)) {
continue;
}
Object value = values.get(i);
if (value instanceof Literal) {
buildMutation(mutation, column, ((Literal) value).getValue());
} else {
buildMutation(mutation, column, value);
}
}
writer.addMutation(mutation);
}
use of org.teiid.language.Literal in project teiid by teiid.
the class SubstringFunctionModifier method translate.
@Override
public List<?> translate(Function function) {
this.modify(function);
Expression from = function.getParameters().get(1);
Boolean isFromNegative = isNegative(from);
Function length = new Function(SourceSystemFunctions.LENGTH, Arrays.asList(function.getParameters().get(0)), TypeFacility.RUNTIME_TYPES.INTEGER);
if (function.getParameters().size() == 2 && (isFromNegative == null || isFromNegative)) {
// couchbase does not handle default length with a negative from index
function.getParameters().add(length);
}
if (function.getParameters().size() == 3) {
// case when length > LENGTH(string) - start + 1 then LENGTH(string) - start + 1 case when length > 0 then length end
Expression forLength = function.getParameters().get(2);
List<SearchedWhenClause> clauses = new ArrayList<SearchedWhenClause>(2);
Boolean isNegative = isNegative(forLength);
Expression adjustedFrom = from;
if (isFromNegative == null || isFromNegative) {
adjustedFrom = new SearchedCase(Arrays.asList(new SearchedWhenClause(new Comparison(from, new Literal(0, TypeFacility.RUNTIME_TYPES.INTEGER), Operator.LT), new Function(SourceSystemFunctions.ADD_OP, Arrays.asList(new Function(SourceSystemFunctions.ADD_OP, Arrays.asList(length, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER), from), TypeFacility.RUNTIME_TYPES.INTEGER))), from, TypeFacility.RUNTIME_TYPES.INTEGER);
}
Expression maxLength = new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(length, new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(adjustedFrom, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER);
clauses.add(new SearchedWhenClause(new Comparison(forLength, maxLength, Operator.GT), maxLength));
Expression defaultExpr = null;
if (isNegative == null) {
clauses.add(new SearchedWhenClause(new Comparison(forLength, new Literal(0, TypeFacility.RUNTIME_TYPES.INTEGER), Operator.GT), forLength));
} else if (isNegative) {
// TODO: could be done in the rewriter
return Arrays.asList(new Literal(null, TypeFacility.RUNTIME_TYPES.STRING));
} else {
defaultExpr = forLength;
}
SearchedCase sc = new SearchedCase(clauses, defaultExpr, TypeFacility.RUNTIME_TYPES.INTEGER);
function.getParameters().set(2, sc);
}
Expression adjustedFrom = function.getParameters().get(1);
if (isFromNegative == null) {
// case when start > 0 then start - 1 else start end
SearchedCase sc = new SearchedCase(Arrays.asList(new SearchedWhenClause(new Comparison(adjustedFrom, new Literal(0, TypeFacility.RUNTIME_TYPES.INTEGER), Operator.GT), new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(adjustedFrom, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER))), from, TypeFacility.RUNTIME_TYPES.INTEGER);
function.getParameters().set(1, sc);
} else if (!isFromNegative) {
function.getParameters().set(1, new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(adjustedFrom, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER));
}
return null;
}
use of org.teiid.language.Literal in project teiid by teiid.
the class S3ProcedureExecution method invokeHTTP.
protected BinaryWSProcedureExecution invokeHTTP(String method, String uri, Object payload, Map<String, String> headers) throws TranslatorException {
Map<String, List<String>> targetHeaders = new HashMap<String, List<String>>();
headers.forEach((k, v) -> targetHeaders.put(k, Arrays.asList(v)));
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_WS, MessageLevel.DETAIL)) {
try {
LogManager.logDetail(LogConstants.CTX_WS, "Source-URL=", // $NON-NLS-1$ //$NON-NLS-2$
URLDecoder.decode(uri, "UTF-8"));
} catch (UnsupportedEncodingException e) {
}
}
List<Argument> parameters = new ArrayList<Argument>();
parameters.add(new Argument(Direction.IN, new Literal(method, TypeFacility.RUNTIME_TYPES.STRING), null));
parameters.add(new Argument(Direction.IN, new Literal(payload, TypeFacility.RUNTIME_TYPES.OBJECT), null));
parameters.add(new Argument(Direction.IN, new Literal(uri, TypeFacility.RUNTIME_TYPES.STRING), null));
parameters.add(new Argument(Direction.IN, new Literal(true, TypeFacility.RUNTIME_TYPES.BOOLEAN), null));
// the engine currently always associates out params at resolve time even if the
// values are not directly read by the call
parameters.add(new Argument(Direction.OUT, TypeFacility.RUNTIME_TYPES.STRING, null));
Call call = this.ef.getLanguageFactory().createCall("invokeHttp", parameters, null);
BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.ec, null, this.conn);
execution.setUseResponseContext(true);
execution.setCustomHeaders(targetHeaders);
return execution;
}
use of org.teiid.language.Literal in project teiid by teiid.
the class SimpleDBUpdateVisitor method visit.
@Override
public void visit(SetClause obj) {
Column column = obj.getSymbol().getMetadataObject();
if (obj.getValue() instanceof Literal) {
try {
Literal l = (Literal) obj.getValue();
this.attributes.put(SimpleDBMetadataProcessor.getName(column), SimpleDBDataTypeManager.convertToSimpleDBType(l.getValue(), column.getJavaType()));
} catch (TranslatorException e) {
this.exceptions.add(e);
}
} else if (obj.getValue() instanceof Array) {
try {
Array array = (Array) obj.getValue();
String[] result = SimpleDBInsertVisitor.getValuesArray(array);
this.attributes.put(SimpleDBMetadataProcessor.getName(column), result);
} catch (TranslatorException e) {
this.exceptions.add(e);
}
} else {
this.exceptions.add(new TranslatorException(SimpleDBPlugin.Event.TEIID24001, SimpleDBPlugin.Util.gs(SimpleDBPlugin.Event.TEIID24001)));
}
}
Aggregations