Search in sources :

Example 61 with Literal

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;
}
Also used : Literal(org.teiid.language.Literal) SubqueryIn(org.teiid.language.SubqueryIn) SubqueryComparison(org.teiid.language.SubqueryComparison) BigDecimal(java.math.BigDecimal)

Example 62 with Literal

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')");
}
Also used : Literal(org.teiid.language.Literal) Test(org.junit.Test)

Example 63 with Literal

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;
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 64 with Literal

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;
}
Also used : Call(org.teiid.language.Call) Argument(org.teiid.language.Argument) Literal(org.teiid.language.Literal) BinaryWSProcedureExecution(org.teiid.translator.ws.BinaryWSProcedureExecution) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 65 with Literal

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());
    }
}
Also used : Array(org.teiid.language.Array) EdmType(org.odata4j.edm.EdmType) Expression(org.teiid.language.Expression) OCollection(org.odata4j.core.OCollection) Literal(org.teiid.language.Literal) EdmCollectionType(org.odata4j.edm.EdmCollectionType) EdmSimpleType(org.odata4j.edm.EdmSimpleType) OObject(org.odata4j.core.OObject)

Aggregations

Literal (org.teiid.language.Literal)82 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)18 Expression (org.teiid.language.Expression)17 TranslatorException (org.teiid.translator.TranslatorException)16 Function (org.teiid.language.Function)15 Argument (org.teiid.language.Argument)12 ColumnReference (org.teiid.language.ColumnReference)10 Column (org.teiid.metadata.Column)10 Comparison (org.teiid.language.Comparison)9 ExpressionValueSource (org.teiid.language.ExpressionValueSource)7 List (java.util.List)5 Call (org.teiid.language.Call)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 BinaryWSProcedureExecution (org.teiid.translator.ws.BinaryWSProcedureExecution)4 DBCollection (com.mongodb.DBCollection)3 Timestamp (java.sql.Timestamp)3 Array (org.teiid.language.Array)3 Command (org.teiid.language.Command)3 Insert (org.teiid.language.Insert)3