Skip to content

Commit

Permalink
TEIID-5448: Fixing nested table delete/update from infinispan (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
rareddy authored and shawkins committed Aug 28, 2018
1 parent 85310f6 commit 4a49e8d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
2 changes: 2 additions & 0 deletions connectors/infinispan/translator-infinispan-hotrod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@
<dependency>
<groupId>org.teiid.connectors</groupId>
<artifactId>connector-infinispan-hotrod</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.teiid.connectors</groupId>
<artifactId>connector-infinispan-hotrod</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ public boolean matches(Map<String, Object> parentProperties, Map<String, Object>
}

for (Column column : childTable.getMetadataObject().getColumns()) {
tuple.add(i++, childProperties.get(MarshallerBuilder.getDocumentAttributeName(column, true, metadata)));
if (ProtobufMetadataProcessor.isPseudo(column)) {
Column parentColumn = IckleConversionVisitor.normalizePseudoColumn(column, this.metadata);
tuple.add(i++, parentProperties.get(MarshallerBuilder.getDocumentAttributeName(parentColumn, false, metadata)));
} else {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ public void visit(DerivedColumn obj) {
this.exceptions.add(new TranslatorException(InfinispanPlugin.Util
.gs(InfinispanPlugin.Event.TEIID25001, column.getName())));
}
column = normalizePseudoColumn(column);
try {
column = normalizePseudoColumn(column, this.metadata);
} catch (TranslatorException e1) {
this.exceptions.add(e1);
}
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()));
Expand Down Expand Up @@ -311,17 +315,13 @@ else if (obj.getExpression() instanceof Function) {
}
}

Column normalizePseudoColumn(Column column) {
static Column normalizePseudoColumn(Column column, RuntimeMetadata metadata) throws TranslatorException {
String pseudo = ProtobufMetadataProcessor.getPseudo(column);
if (pseudo != null) {
try {
Table columnParent = (Table)column.getParent();
Table pseudoColumnParent = this.metadata.getTable(
ProtobufMetadataProcessor.getMerge(columnParent));
return pseudoColumnParent.getColumnByName(getName(column));
} catch (TranslatorException e) {
this.exceptions.add(e);
}
Table columnParent = (Table)column.getParent();
Table pseudoColumnParent = metadata.getTable(
ProtobufMetadataProcessor.getMerge(columnParent));
return pseudoColumnParent.getColumnByName(getRecordName(column));
}
return column;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,9 @@ static void paginateDeleteResults(RemoteCache<Object, Object> cache, String quer
try {
int offset = 0;
while (true) {

query.startOffset(offset);
query.maxResults(batchSize);

int cnt = query.getResultSize();
List<Object> values = query.list();

if (values == null || values.isEmpty()) {
Expand All @@ -363,7 +361,6 @@ static void paginateDeleteResults(RemoteCache<Object, Object> cache, String quer
for (Object doc : values) {
task.run(doc);
}

}
} catch (Throwable e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private InfinispanDocument buildInsertPayload(Insert obj, List<Expression> value
}
updateDocument(targetDocument, column, value);

if (column.equals(pkColumn) || pkColumn.equals(normalizePseudoColumn(column))) {
if (column.equals(pkColumn) || pkColumn.equals(normalizePseudoColumn(column, this.metadata))) {
targetDocument.setIdentifier(value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public void process(MetadataFactory metadataFactory, InfinispanConnection connec
throws TranslatorException {

String protobufFile = getProtoFilePath();
String cacheName = null;
if (connection != null) {
cacheName = connection.getCache().getName();
}
String protoContents = null;
if( protobufFile != null && !protobufFile.isEmpty()) {
File f = new File(protobufFile);
Expand All @@ -145,7 +149,7 @@ public void process(MetadataFactory metadataFactory, InfinispanConnection connec
}
this.protoResource = new ProtobufResource(this.protobufName != null ? this.protobufName : protobufFile,
protoContents);
toTeiidSchema(protobufFile, protoContents, metadataFactory);
toTeiidSchema(protobufFile, protoContents, metadataFactory, cacheName);
} else if( this.protobufName != null) {
// Read from cache
boolean added = false;
Expand All @@ -158,7 +162,7 @@ public void process(MetadataFactory metadataFactory, InfinispanConnection connec
protobufFile = (String)key;
protoContents = (String)metadataCache.get(key);
// read all the schemas
toTeiidSchema(protobufFile, protoContents, metadataFactory);
toTeiidSchema(protobufFile, protoContents, metadataFactory, cacheName);
this.protoResource = new ProtobufResource(protobufFile, protoContents);
added = true;
break;
Expand All @@ -169,7 +173,8 @@ public void process(MetadataFactory metadataFactory, InfinispanConnection connec
InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25012, this.protobufName));
}
} else if (this.protoResource != null) {
toTeiidSchema(this.protoResource.getIdentifier(), this.protoResource.getContents(), metadataFactory);
toTeiidSchema(this.protoResource.getIdentifier(), this.protoResource.getContents(), metadataFactory,
cacheName);
} else {
// expand the error message
throw new TranslatorException(InfinispanPlugin.Event.TEIID25011,
Expand All @@ -188,8 +193,8 @@ static <T> List<T> filter(List<? super TypeElement> input, Class<T> ofType) {
return ts;
}

private void toTeiidSchema(String name, String contents,
MetadataFactory mf) throws TranslatorException {
private void toTeiidSchema(String name, String contents, MetadataFactory mf, String cacheName)
throws TranslatorException {

LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Processing Proto file:", name, " with contents\n", contents);

Expand All @@ -210,7 +215,7 @@ private void toTeiidSchema(String name, String contents,
// of child tables, as they will be part of parent, and we do not want discrepancy
// in metadata, as both parent child must be in single cache.
if (getParentTag(t) == -1) {
t.setProperty(CACHE, t.getName());
t.setProperty(CACHE, (cacheName == null ? t.getName() : cacheName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,19 @@ public void testServer() throws Exception {
assertArrayEquals(new Object[] {new Integer(1), "one"}, exec.next().toArray());
assertArrayEquals(new Object[] {new Integer(3), "two"}, exec.next().toArray());
assertNull(exec.next());

command = UTILITY.parseCommand("DELETE FROM G4 where e2 = 'two' AND G2_e1 = 2");
update = EF.createUpdateExecution(command, EC, METADATA, connection);
update.execute();

command = UTILITY.parseCommand("SELECT e1, e2 FROM G4");
exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
exec.execute();

assertArrayEquals(new Object[] {new Integer(1), "one"}, exec.next().toArray());
assertNull(exec.next());

// cascade deletes G4
command = UTILITY.parseCommand("DELETE FROM G2 where e1 = 1");
update = EF.createUpdateExecution(command, EC, METADATA, connection);
update.execute();
Expand Down Expand Up @@ -258,7 +270,6 @@ public void testServer() throws Exception {
exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
exec.execute();

assertArrayEquals(new Object[] {new Integer(3), "two"}, exec.next().toArray());
assertArrayEquals(new Object[] {new Integer(5), "upsert"}, exec.next().toArray());
assertNull(exec.next());

Expand Down

0 comments on commit 4a49e8d

Please sign in to comment.