use of org.teiid.metadata.Column 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.metadata.Column in project teiid by teiid.
the class IckleConversionVisitor method visit.
@Override
public void visit(Comparison obj) {
if (obj.getOperator() == Operator.EQ && obj.getLeftExpression() instanceof ColumnReference && obj.getRightExpression() instanceof ColumnReference) {
// this typically is join.
Column left = ((ColumnReference) obj.getLeftExpression()).getMetadataObject();
Column right = ((ColumnReference) obj.getRightExpression()).getMetadataObject();
if (getQualifiedName(left).equals(getQualifiedName(right))) {
return;
}
}
super.visit(obj);
}
use of org.teiid.metadata.Column 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)));
}
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class IckleConversionVisitor method addSelectedColumns.
StringBuilder addSelectedColumns(StringBuilder sb) {
sb.append(SQLConstants.Reserved.SELECT).append(Tokens.SPACE);
boolean first = true;
for (Expression expr : this.projectedExpressions) {
if (!first) {
sb.append(Tokens.COMMA).append(Tokens.SPACE);
}
if (expr instanceof ColumnReference) {
Column column = ((ColumnReference) expr).getMetadataObject();
String nis = getQualifiedName(column);
sb.append(nis);
} else if (expr instanceof Function) {
Function func = (Function) expr;
sb.append(func.getName()).append(Tokens.LPAREN);
if (func.getParameters().isEmpty() && SQLConstants.NonReserved.COUNT.equalsIgnoreCase(func.getName())) {
sb.append(Tokens.ALL_COLS);
} else {
ColumnReference columnRef = (ColumnReference) func.getParameters().get(0);
Column column = columnRef.getMetadataObject();
String nis = getQualifiedName(column);
sb.append(nis);
}
sb.append(Tokens.RPAREN);
}
first = false;
}
return sb;
}
use of org.teiid.metadata.Column in project teiid by teiid.
the class InfinispanExecutionFactory method getMetadata.
@Override
public void getMetadata(MetadataFactory metadataFactory, InfinispanConnection conn) throws TranslatorException {
ProtobufMetadataProcessor metadataProcessor = (ProtobufMetadataProcessor) getMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, metadataFactory.getModelProperties(), "importer");
// This block is only invoked when NATIVE metadata is defined, by the time code got here if we have
// tables already in schema, then user defined through other metadata repositories. In this case,
// a .proto file need to be generated based on schema, then use that to generate final metadata and
// register the .proto with the Infinispan
Schema schema = metadataFactory.getSchema();
ProtobufResource resource = null;
ArrayList<Table> removedTables = new ArrayList<>();
if (schema.getTables() != null && !schema.getTables().isEmpty()) {
SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
stpp.setIndexMessages(true);
resource = stpp.process(metadataFactory, conn);
metadataProcessor.setProtobufResource(resource);
ArrayList<Table> tables = new ArrayList<>(schema.getTables().values());
for (Table t : tables) {
// remove the previous tables, as we want to introduce them with necessary
// extension metadata generated with generated .proto file. As some of the default
// extension metadata can be added.
removedTables.add(schema.removeTable(t.getName()));
}
}
metadataProcessor.process(metadataFactory, conn);
// may be not carried forward, we need to make sure we copy those back.
for (Table oldT : removedTables) {
Table newT = schema.getTable(oldT.getName());
Map<String, String> properties = oldT.getProperties();
for (Map.Entry<String, String> entry : properties.entrySet()) {
newT.setProperty(entry.getKey(), entry.getValue());
}
newT.setSupportsUpdate(oldT.supportsUpdate());
if (oldT.getAnnotation() != null) {
newT.setAnnotation(oldT.getAnnotation());
}
List<Column> columns = oldT.getColumns();
for (Column c : columns) {
Column newCol = newT.getColumnByName(c.getName());
if (newCol != null) {
Map<String, String> colProperties = c.getProperties();
for (Map.Entry<String, String> entry : colProperties.entrySet()) {
newCol.setProperty(entry.getKey(), entry.getValue());
}
newCol.setUpdatable(c.isUpdatable());
if (c.getAnnotation() != null) {
newCol.setAnnotation(c.getAnnotation());
}
}
}
}
resource = metadataProcessor.getProtobufResource();
if (resource == null) {
SchemaToProtobufProcessor stpp = new SchemaToProtobufProcessor();
resource = stpp.process(metadataFactory, conn);
}
// register protobuf
if (resource != null) {
conn.registerProtobufFile(resource);
}
}
Aggregations