use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class InfinispanUpdateVisitor method visit.
@Override
public void visit(Insert obj) {
this.operationType = OperationType.INSERT;
if (obj.isUpsert()) {
this.operationType = OperationType.UPSERT;
}
visitNode(obj.getTable());
Column pkColumn = getPrimaryKey();
if (pkColumn == null) {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25013, getParentTable().getName())));
return;
}
if (obj.getParameterValues() == null) {
List<Expression> values = ((ExpressionValueSource) obj.getValueSource()).getValues();
this.insertPayload = buildInsertPayload(obj, values);
if (this.insertPayload != null) {
this.identity = this.insertPayload.getIdentifier();
}
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class TeiidTableMarsheller method readDocument.
static void readDocument(RawProtoStreamReader in, InfinispanDocument document, TreeMap<Integer, TableWireFormat> columnMap, DocumentFilter filter) throws IOException {
while (true) {
int tag = in.readTag();
if (tag == 0) {
break;
}
TableWireFormat twf = columnMap.get(tag);
if (twf == null) {
throw new IOException("Error in wireformat");
}
if (twf.isNested()) {
InfinispanDocument child = new InfinispanDocument(twf.getAttributeName(), twf.getNestedWireMap(), document);
int length = in.readRawVarint32();
int oldLimit = in.pushLimit(length);
readDocument(in, child, twf.getNestedWireMap(), filter);
try {
if (filter == null) {
document.addChildDocument(twf.getAttributeName(), child);
document.incrementUpdateCount(twf.getAttributeName(), true);
} else {
boolean matched = filter.matches(document.getProperties(), child.getProperties());
if (matched) {
if (filter.action() == Action.ADD) {
// SELECT
document.addChildDocument(twf.getAttributeName(), child);
} else if (filter.action() == Action.REMOVE) {
// DELETE
// no op, ie removed.
} else {
// UPDATE
document.addChildDocument(twf.getAttributeName(), child);
}
} else {
if (filter.action() == Action.ALWAYSADD || filter.action() == Action.REMOVE) {
document.addChildDocument(twf.getAttributeName(), child);
}
}
// keep track all the adds and removed based on this filter
child.setMatched(matched);
document.incrementUpdateCount(twf.getAttributeName(), matched);
}
} catch (TranslatorException e) {
throw new IOException(e.getCause());
}
in.checkLastTagWas(0);
in.popLimit(oldLimit);
continue;
}
switch(twf.getProtobufType()) {
case DOUBLE:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readDouble()));
break;
case FLOAT:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readFloat()));
break;
case BOOL:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readBool()));
break;
case STRING:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readString()));
break;
case BYTES:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readByteArray()));
break;
case INT32:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readInt32()));
break;
case SFIXED32:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readSFixed32()));
break;
case FIXED32:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readFixed32()));
break;
case UINT32:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readUInt32()));
break;
case SINT32:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readSInt32()));
break;
case INT64:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readInt64()));
break;
case UINT64:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readUInt64()));
break;
case FIXED64:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readFixed64()));
break;
case SFIXED64:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readSFixed64()));
break;
case SINT64:
document.addProperty(tag, ProtobufDataManager.convertToRuntime(twf.expectedType(), in.readSInt64()));
break;
default:
throw new IOException("Unexpected field type : " + twf.getProtobufType());
}
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class ComplexDocumentFilter method matches.
@Override
public boolean matches(Map<String, Object> parentProperties, Map<String, Object> childProperties) throws TranslatorException {
try {
List<Object> tuple = new ArrayList<>();
int i = 0;
for (Column column : parentTable.getMetadataObject().getColumns()) {
tuple.add(i++, parentProperties.get(MarshallerBuilder.getDocumentAttributeName(column, false, metadata)));
}
for (Column column : childTable.getMetadataObject().getColumns()) {
tuple.add(i++, childProperties.get(MarshallerBuilder.getDocumentAttributeName(column, true, metadata)));
}
org.teiid.query.util.CommandContext cc = new org.teiid.query.util.CommandContext();
final Evaluator evaluator = new Evaluator(elementMap, null, cc);
return evaluator.evaluate(criteria, tuple);
} catch (ExpressionEvaluationException e) {
throw new TranslatorException(e);
} catch (BlockedException e) {
throw new TranslatorException(e);
} catch (TeiidComponentException e) {
throw new TranslatorException(e);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class IckleConversionVisitor method visit.
@Override
public void visit(NamedTable obj) {
this.queriedTable = obj;
if (obj.getCorrelationName() == null) {
obj.setCorrelationName(obj.getMetadataObject().getName().toLowerCase() + "_" + aliasCounter.getAndIncrement());
}
if (this.rootNode == null) {
String messageName = null;
String aliasName = null;
String mergedTableName = ProtobufMetadataProcessor.getMerge(obj.getMetadataObject());
if (mergedTableName == null) {
aliasName = obj.getCorrelationName();
messageName = getMessageName(obj.getMetadataObject());
this.parentTable = obj;
this.rootNode = new DocumentNode(obj.getMetadataObject(), true);
this.joinedNode = this.rootNode;
// check to see if there is one-2-one rows
Set<String> tags = new HashSet<>();
for (Column column : obj.getMetadataObject().getColumns()) {
if (ProtobufMetadataProcessor.getParentTag(column) != -1) {
String childMessageName = ProtobufMetadataProcessor.getMessageName(column);
if (!tags.contains(childMessageName)) {
tags.add(childMessageName);
// TODO: DocumentNode needs to be refactored to just take name, not table
Table t = new Table();
t.setName(childMessageName);
this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(t, false));
}
}
}
} else {
try {
Table mergedTable = this.metadata.getTable(mergedTableName);
messageName = getMessageName(mergedTable);
aliasName = mergedTable.getName().toLowerCase() + "_" + aliasCounter.getAndIncrement();
this.parentTable = new NamedTable(mergedTable.getName(), aliasName, mergedTable);
this.rootNode = new DocumentNode(mergedTable, true);
this.joinedNode = this.rootNode.joinWith(JoinType.INNER_JOIN, new DocumentNode(obj.getMetadataObject(), true));
this.nested = true;
} catch (TranslatorException e) {
this.exceptions.add(e);
}
}
buffer.append(messageName);
if (aliasName != null) {
buffer.append(Tokens.SPACE);
buffer.append(aliasName);
}
if (this.includePK) {
KeyRecord pk = this.parentTable.getMetadataObject().getPrimaryKey();
if (pk != null) {
for (Column column : pk.getColumns()) {
projectedExpressions.add(new ColumnReference(obj, column.getName(), column, column.getJavaType()));
}
}
}
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class IckleConversionVisitor method visit.
@Override
public void visit(DerivedColumn obj) {
if (obj.getExpression() instanceof ColumnReference) {
Column column = ((ColumnReference) obj.getExpression()).getMetadataObject();
if (!column.isSelectable()) {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25001, column.getName())));
}
column = normalizePseudoColumn(column);
if (!this.includePK || !isPartOfPrimaryKey(column.getName())) {
if (column.getParent().equals(this.parentTable.getMetadataObject())) {
this.projectedExpressions.add(new ColumnReference(this.parentTable, column.getName(), column, column.getJavaType()));
} else {
this.projectedExpressions.add(new ColumnReference(this.queriedTable, column.getName(), column, column.getJavaType()));
}
}
boolean nested = false;
if (ProtobufMetadataProcessor.getParentTag(column) != -1 || ProtobufMetadataProcessor.getParentTag((Table) column.getParent()) != -1) {
this.avoidProjection = true;
nested = true;
}
try {
this.projectedDocumentAttributes.put(MarshallerBuilder.getDocumentAttributeName(column, nested, this.metadata), column.getJavaType());
} catch (TranslatorException e) {
this.exceptions.add(e);
}
} else if (obj.getExpression() instanceof Function) {
if (!this.parentTable.equals(this.queriedTable)) {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Event.TEIID25008, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25008)));
}
AggregateFunction func = (AggregateFunction) obj.getExpression();
this.projectedExpressions.add(func);
// Aggregate functions can not be part of the implicit query projection when the complex object is involved
// thus not adding to projectedDocumentAttributes. i.e. sum(g2.g3.e1) is not supported by Infinispan AFAIK.
this.projectedDocumentAttributes.put(obj.getAlias(), func.getType());
} else {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25002, obj)));
}
}
Aggregations