use of org.teiid.language.Literal in project teiid by teiid.
the class PhoenixExecutionFactory method translate.
/**
* Adding a specific workaround for just Pheonix and BigDecimal.
*/
@Override
public List<?> translate(LanguageObject obj, ExecutionContext context) {
if (obj instanceof SubqueryIn) {
SubqueryIn in = (SubqueryIn) obj;
return Arrays.asList(new SubqueryComparison(in.getLeftExpression(), in.isNegated() ? Operator.NE : Operator.EQ, in.isNegated() ? Quantifier.ALL : Quantifier.SOME, in.getSubquery()));
}
if (!(obj instanceof Literal)) {
return super.translate(obj, context);
}
Literal l = (Literal) obj;
if (l.isBindEligible() || l.getType() != TypeFacility.RUNTIME_TYPES.BIG_DECIMAL) {
return super.translate(obj, context);
}
BigDecimal bd = ((BigDecimal) l.getValue());
if (bd.scale() == 0) {
l.setValue(bd.setScale(1));
}
return null;
}
use of org.teiid.language.Literal in project teiid by teiid.
the class TestSQLConversionVisitor method testDayOfYear.
@Test
public void testDayOfYear() throws Exception {
Literal arg1 = LANG_FACTORY.createLiteral(TimestampUtil.createTimestamp(117, 0, 13, 10, 5, 0, 10000000), Timestamp.class);
// $NON-NLS-1$
helpTestMod(arg1, SourceSystemFunctions.DAYOFYEAR, "day_of_year(timestamp '2017-01-13 10:05:00.01')");
}
use of org.teiid.language.Literal in project teiid by teiid.
the class BaseQueryExecution method invokeHTTP.
protected BinaryWSProcedureExecution invokeHTTP(String method, String uri, String payload, Map<String, List<String>> headers) throws TranslatorException {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)) {
try {
LogManager.logDetail(LogConstants.CTX_ODATA, "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.STRING), 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.translator.getLanguageFactory().createCall(ODataExecutionFactory.INVOKE_HTTP, parameters, null);
BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.executionContext, null, this.connection);
execution.setUseResponseContext(true);
execution.setCustomHeaders(headers);
execution.execute();
return execution;
}
use of org.teiid.language.Literal in project teiid by teiid.
the class BaseQueryExecution method executeDirect.
protected BinaryWSProcedureExecution executeDirect(String method, String uri, String payload, Map<String, List<String>> headers) throws TranslatorException {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_ODATA, MessageLevel.DETAIL)) {
try {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_ODATA, "Source-URL=", 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.STRING), 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.translator.getLanguageFactory().createCall(ODataExecutionFactory.INVOKE_HTTP, parameters, null);
BinaryWSProcedureExecution execution = new BinaryWSProcedureExecution(call, this.metadata, this.executionContext, null, this.connection);
execution.setUseResponseContext(true);
execution.setCustomHeaders(headers);
execution.execute();
return execution;
}
use of org.teiid.language.Literal in project teiid by teiid.
the class ODataUpdateVisitor method readProperty.
private OProperty<?> readProperty(Column column, Object value) {
if (value instanceof Array) {
EdmType componentType = ODataTypeManager.odataType(column.getRuntimeType());
if (componentType instanceof EdmCollectionType) {
componentType = ((EdmCollectionType) componentType).getItemType();
}
OCollection.Builder<OObject> b = OCollections.newBuilder(componentType);
List<Expression> values = ((Array) value).getExpressions();
for (int i = 0; i < values.size(); i++) {
Literal literal = (Literal) values.get(i);
b.add(OSimpleObjects.create((EdmSimpleType<?>) componentType, literal.getValue()));
}
return OProperties.collection(column.getName(), new EdmCollectionType(CollectionKind.Collection, componentType), b.build());
} else {
Literal literal = (Literal) value;
return OProperties.simple(column.getName(), literal.getValue());
}
}
Aggregations