Search in sources :

Example 1 with JSONBuilder

use of org.teiid.query.function.JSONFunctionMethods.JSONBuilder in project teiid by teiid.

the class Evaluator method evaluateJSONObject.

private Object evaluateJSONObject(List<?> tuple, JSONObject function, JSONBuilder builder) throws ExpressionEvaluationException, BlockedException, TeiidComponentException, FunctionExecutionException {
    List<DerivedColumn> args = function.getArgs();
    Evaluator.NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args, false, false);
    boolean returnValue = false;
    try {
        if (builder == null) {
            returnValue = true;
            // preevaluate subqueries to prevent blocked exceptions
            for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(function)) {
                evaluateSubquery(container, tuple);
            }
            builder = new JSONBuilder(context.getBufferManager());
        }
        builder.start(false);
        for (NameValuePair<Object> nameValuePair : nameValuePairs) {
            addValue(tuple, builder, nameValuePair.name, nameValuePair.value);
        }
        builder.end(false);
        if (returnValue) {
            ClobType result = builder.close(context);
            builder = null;
            return result;
        }
        return null;
    } catch (TeiidProcessingException e) {
        throw new FunctionExecutionException(e);
    } finally {
        if (returnValue && builder != null) {
            builder.remove();
        }
    }
}
Also used : JSONBuilder(org.teiid.query.function.JSONFunctionMethods.JSONBuilder) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) LanguageObject(org.teiid.query.sql.LanguageObject) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 2 with JSONBuilder

use of org.teiid.query.function.JSONFunctionMethods.JSONBuilder in project teiid by teiid.

the class JSONArrayAgg method addInputDirect.

/**
 * @throws TeiidProcessingException
 * @throws TeiidComponentException
 * @see org.teiid.query.function.aggregate.AggregateFunction#addInputDirect(List, CommandContext, CommandContext)
 */
public void addInputDirect(Object input, List<?> tuple, CommandContext commandContext) throws TeiidComponentException, TeiidProcessingException {
    if (concat == null) {
        concat = new JSONBuilder(commandContext.getBufferManager());
        concat.start(true);
    }
    concat.addValue(input);
}
Also used : JSONBuilder(org.teiid.query.function.JSONFunctionMethods.JSONBuilder)

Example 3 with JSONBuilder

use of org.teiid.query.function.JSONFunctionMethods.JSONBuilder in project teiid by teiid.

the class Evaluator method jsonArray.

public static ClobType jsonArray(CommandContext context, Function f, Object[] vals, JSONBuilder builder, Evaluator eval, List<?> tuple) throws TeiidProcessingException, BlockedException, TeiidComponentException {
    boolean returnValue = false;
    try {
        if (builder == null) {
            returnValue = true;
            if (eval != null) {
                // preevaluate subqueries to prevent blocked exceptions
                for (SubqueryContainer<?> container : ValueIteratorProviderCollectorVisitor.getValueIteratorProviders(f)) {
                    eval.evaluateSubquery(container, tuple);
                }
            }
            builder = new JSONBuilder(context.getBufferManager());
        }
        builder.start(true);
        for (Object object : vals) {
            if (eval != null) {
                eval.addValue(tuple, builder, null, object);
            } else {
                builder.addValue(object);
            }
        }
        builder.end(true);
        if (returnValue) {
            ClobType result = builder.close(context);
            builder = null;
            return result;
        }
        return null;
    } finally {
        if (returnValue && builder != null) {
            builder.remove();
        }
    }
}
Also used : JSONBuilder(org.teiid.query.function.JSONFunctionMethods.JSONBuilder) LanguageObject(org.teiid.query.sql.LanguageObject)

Aggregations

JSONBuilder (org.teiid.query.function.JSONFunctionMethods.JSONBuilder)3 LanguageObject (org.teiid.query.sql.LanguageObject)2 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1