use of org.teiid.language.Array 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)));
}
}
use of org.teiid.language.Array in project teiid by teiid.
the class TestDependentJoins method helpTestPushdown.
private void helpTestPushdown(boolean supportsArrayType) {
// Create query
// $NON-NLS-1$
String sql = "SELECT pm1.g1.e1 FROM /*+ MAKEIND */ pm1.g1, pm2.g1 WHERE pm1.g1.e1 = pm2.g1.e1 AND pm1.g1.e2=pm2.g1.e2 order by pm1.g1.e1";
// Create expected results
List[] expected = new List[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "a" }) };
// Construct data manager with data
HardcodedDataManager dataManager = new HardcodedDataManager(RealMetadataFactory.example1Cached());
dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM g1 AS g_0 ORDER BY c_0, c_1", new List[] { Arrays.asList("a", 1), Arrays.asList("b", 2) });
if (supportsArrayType) {
dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM g1 AS g_0 WHERE (g_0.e1, g_0.e2) = (?, ?) ORDER BY c_0, c_1", new List[] { Arrays.asList("a", 1) });
} else {
dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM g1 AS g_0 WHERE g_0.e1 = ? AND g_0.e2 = ? ORDER BY c_0, c_1", new List[] { Arrays.asList("a", 1) });
}
BasicSourceCapabilities bsc = TestOptimizer.getTypicalCapabilities();
bsc.setCapabilitySupport(Capability.DEPENDENT_JOIN, true);
bsc.setCapabilitySupport(Capability.ARRAY_TYPE, supportsArrayType);
bsc.setSourceProperty(Capability.MAX_DEPENDENT_PREDICATES, 1);
bsc.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, 1);
DefaultCapabilitiesFinder dcf = new DefaultCapabilitiesFinder(bsc);
// Plan query
ProcessorPlan plan = TestProcessor.helpGetPlan(sql, RealMetadataFactory.example1Cached(), dcf);
TestOptimizer.checkDependentJoinCount(plan, 1);
// Run query
TestProcessor.helpProcess(plan, dataManager, expected);
Select s = (Select) dataManager.getPushdownCommands().get(1);
assertEquals(1, s.getDependentValues().size());
List<? extends List<?>> vals = s.getDependentValues().values().iterator().next();
assertEquals(2, vals.size());
if (supportsArrayType) {
Comparison comp = (Comparison) s.getWhere();
Parameter p = (Parameter) ((Array) comp.getRightExpression()).getExpressions().get(0);
assertEquals(0, p.getValueIndex());
assertNotNull(s.getDependentValues().get(p.getDependentValueId()));
}
}
use of org.teiid.language.Array in project teiid by teiid.
the class SwaggerProcedureExecution method buildWSExecution.
private BinaryWSProcedureExecution buildWSExecution(Call obj) throws TranslatorException {
Procedure procedure = obj.getMetadataObject();
String uri = procedure.getProperty(RestMetadataExtension.URI, false);
String method = procedure.getProperty(RestMetadataExtension.METHOD, false);
StringBuilder queryParameters = new StringBuilder();
StringBuilder formParameters = new StringBuilder();
Map<String, List<String>> headers = new HashMap<String, List<String>>();
Object payload = null;
// body payload document
SwaggerBodyInputDocument input = null;
final List<Argument> params = obj.getArguments();
if (params != null && params.size() != 0) {
Argument param = null;
for (int i = 0; i < params.size(); i++) {
param = params.get(i);
ProcedureParameter metadata = param.getMetadataObject();
String argName = WSConnection.Util.httpURLEncode(param.getMetadataObject().getName());
if (param.getDirection() == Direction.IN || param.getDirection() == Direction.INOUT) {
String in = metadata.getProperty(RestMetadataExtension.PARAMETER_TYPE, false);
if (in.equalsIgnoreCase(RestMetadataExtension.ParameterType.QUERY.name())) {
if (queryParameters.length() != 0) {
// $NON-NLS-1$
queryParameters.append("&");
}
Object value = param.getExpression();
if (value instanceof Array) {
addArgumentValue(argName, (Array) value, metadata.getProperty(SwaggerMetadataProcessor.COLLECION_FORMAT, false), queryParameters);
} else {
String argValue = getURLValue((Literal) value);
queryParameters.append(argName);
queryParameters.append(Tokens.EQ);
queryParameters.append(argValue);
}
} else if (in.equalsIgnoreCase(RestMetadataExtension.ParameterType.PATH.name())) {
String argValue = getURLValue(param.getArgumentValue());
// $NON-NLS-1$ //$NON-NLS-2$
String regex = "\\{" + argName + "\\}";
uri = uri.replaceAll(regex, argValue);
} else if (in.equalsIgnoreCase(RestMetadataExtension.ParameterType.FORM.name()) || in.equalsIgnoreCase(RestMetadataExtension.ParameterType.FORMDATA.name())) {
if (formParameters.length() != 0) {
// $NON-NLS-1$
formParameters.append("&");
}
Object value = param.getExpression();
if (value instanceof Array) {
addArgumentValue(argName, (Array) value, metadata.getProperty(SwaggerMetadataProcessor.COLLECION_FORMAT, false), formParameters);
} else {
formParameters.append(argName);
formParameters.append(Tokens.EQ);
formParameters.append(getURLValue((Literal) value));
}
} else if (in.equalsIgnoreCase(RestMetadataExtension.ParameterType.BODY.name())) {
if (input == null) {
input = new SwaggerBodyInputDocument();
}
Object expr = param.getExpression();
if (expr instanceof Literal) {
expr = ((Literal) expr).getValue();
}
input.addArgument(param.getMetadataObject(), expr);
} else if (in.equalsIgnoreCase(RestMetadataExtension.ParameterType.HEADER.name())) {
String argValue = param.getArgumentValue().getValue().toString();
headers.put(argName, Arrays.asList(argValue));
}
} else {
throw new TranslatorException("Not supported parameter");
}
}
}
String consumes = procedure.getProperty(RestMetadataExtension.CONSUMES, false);
if (consumes == null) {
consumes = "application/json";
}
if (input != null) {
try {
SwaggerSerializer serializer = getSerializer(consumes);
InputStream oos = serializer.serialize(input);
payload = ObjectConverterUtil.convertToString(oos);
} catch (IOException e) {
throw new TranslatorException(e);
}
}
if (payload == null && formParameters.length() > 0) {
payload = formParameters.toString();
}
headers.put("Content-Type", Arrays.asList(consumes));
String produces = procedure.getProperty(RestMetadataExtension.PRODUCES, false);
if (produces == null) {
produces = "application/json";
}
headers.put("Accept", Arrays.asList(produces));
if (queryParameters.length() > 0) {
uri = uri + "?" + queryParameters;
}
return buildInvokeHTTP(method, uri, payload, headers);
}
use of org.teiid.language.Array in project teiid by teiid.
the class TestOracleTranslator method testArrayComparison.
@Test
public void testArrayComparison() throws Exception {
// $NON-NLS-1$
String input = "select intkey from bqt1.smalla where intkey = 5";
// $NON-NLS-1$
String output = "SELECT g_0.IntKey FROM SmallA g_0 WHERE (g_0.IntKey, g_0.IntKey) = ((5, 2))";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Select obj = (Select) commandBuilder.getCommand(input, true, true);
Comparison comp = (Comparison) obj.getWhere();
// modify to an array comparison, since there is not yet parsing support
comp.setLeftExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getLeftExpression(), comp.getLeftExpression())));
comp.setRightExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getRightExpression(), new Literal(2, TypeFacility.RUNTIME_TYPES.INTEGER))));
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
use of org.teiid.language.Array 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