use of org.teiid.language.ColumnReference in project teiid by teiid.
the class ODataQuery method parseKeySegmentFromComparison.
private boolean parseKeySegmentFromComparison(Comparison obj) throws TranslatorException {
if (obj.getOperator().equals(Comparison.Operator.EQ)) {
if (obj.getLeftExpression() instanceof ColumnReference && obj.getRightExpression() instanceof ColumnReference) {
Column left = ((ColumnReference) obj.getLeftExpression()).getMetadataObject();
Column right = ((ColumnReference) obj.getRightExpression()).getMetadataObject();
if (isJoinOrPkColumn(left) && isJoinOrPkColumn(right)) {
// in odata the navigation from parent to child implicit by their keys
return true;
}
}
}
return false;
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class InfinispanQueryExecution method useModifiedGroups.
static void useModifiedGroups(InfinispanConnection connection, ExecutionContext context, RuntimeMetadata metadata, Command command) throws TranslatorException {
BasicCache<String, String> aliasCache = InfinispanDirectQueryExecution.getAliasCache(connection);
CollectorVisitor.collectGroups(command).forEach(namedTable -> {
try {
Table table = InfinispanDirectQueryExecution.getAliasTable(context, metadata, aliasCache, namedTable.getMetadataObject());
Collection<ColumnReference> columns = CollectorVisitor.collectElements(command);
columns.forEach(reference -> {
if (reference.getTable().getMetadataObject().equals(namedTable.getMetadataObject())) {
Column column = table.getColumnByName(reference.getMetadataObject().getName());
reference.getTable().setMetadataObject(table);
reference.setMetadataObject(column);
}
});
namedTable.setMetadataObject(table);
} catch (TranslatorException e) {
LogManager.logError(LogConstants.CTX_CONNECTOR, e, e.getMessage());
}
});
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class InfinispanUpdateExecution method execute.
@Override
public void execute() throws TranslatorException {
if (useAliasCache) {
if (useAliasCache) {
InfinispanQueryExecution.useModifiedGroups(this.connection, this.executionContext, this.metadata, this.command);
}
}
final InfinispanUpdateVisitor visitor = new InfinispanUpdateVisitor(this.metadata);
visitor.append(this.command);
if (!visitor.exceptions.isEmpty()) {
throw visitor.exceptions.get(0);
}
TeiidTableMarsheller marshaller = null;
try {
Table table = visitor.getParentTable();
Column pkColumn = visitor.getPrimaryKey();
if (pkColumn == null) {
throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25013, table.getName()));
}
final String PK = MarshallerBuilder.getDocumentAttributeName(pkColumn, false, this.metadata);
DocumentFilter docFilter = null;
if (visitor.isNestedOperation() && visitor.getWhereClause() != null) {
Action action = Action.ALWAYSADD;
if (command instanceof Delete) {
action = Action.REMOVE;
}
SQLStringVisitor ssv = new SQLStringVisitor() {
@Override
public void visit(ColumnReference obj) {
String groupName = null;
NamedTable group = obj.getTable();
if (group.getCorrelationName() != null) {
groupName = group.getCorrelationName();
} else {
Table groupID = group.getMetadataObject();
if (groupID.getFullName().equals(visitor.getParentTable().getFullName())) {
groupName = visitor.getParentNamedTable().getCorrelationName();
} else {
groupName = visitor.getQueryNamedTable().getCorrelationName();
}
}
buffer.append(groupName).append(Tokens.DOT).append(getName(obj.getMetadataObject()));
}
@Override
public String getName(AbstractMetadataRecord object) {
return object.getName();
}
};
ssv.append(visitor.getWhereClause());
docFilter = new ComplexDocumentFilter(visitor.getParentNamedTable(), visitor.getQueryNamedTable(), this.metadata, ssv.toString(), action);
}
marshaller = MarshallerBuilder.getMarshaller(table, this.metadata, docFilter);
this.connection.registerMarshaller(marshaller);
// if the message in defined in different cache than the default, switch it out now.
final RemoteCache<Object, Object> cache = InfinispanQueryExecution.getCache(table, connection);
if (visitor.getOperationType() == OperationType.DELETE) {
paginateDeleteResults(cache, visitor.getDeleteQuery(), new Task() {
@Override
public void run(Object row) throws TranslatorException {
if (visitor.isNestedOperation()) {
String childName = ProtobufMetadataProcessor.getMessageName(visitor.getQueryTable());
InfinispanDocument document = (InfinispanDocument) row;
cache.replace(document.getProperties().get(PK), document);
// false below means count that not matched, i.e. deleted count
updateCount = updateCount + document.getUpdateCount(childName, false);
} else {
Object key = ((Object[]) row)[0];
cache.remove(key);
updateCount++;
}
}
}, this.executionContext.getBatchSize());
} else if (visitor.getOperationType() == OperationType.UPDATE) {
paginateUpdateResults(cache, visitor.getUpdateQuery(), new Task() {
@Override
public void run(Object row) throws TranslatorException {
InfinispanDocument previous = (InfinispanDocument) row;
Object key = previous.getProperties().get(PK);
int count = previous.merge(visitor.getInsertPayload());
cache.replace(key, previous);
updateCount = updateCount + count;
}
}, this.executionContext.getBatchSize());
} else if (visitor.getOperationType() == OperationType.INSERT) {
performInsert(visitor, table, cache, false, marshaller);
} else if (visitor.getOperationType() == OperationType.UPSERT) {
performInsert(visitor, table, cache, true, marshaller);
}
} finally {
if (marshaller != null) {
this.connection.unRegisterMarshaller(marshaller);
}
}
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class MockConnector method createResultSetExecution.
@Override
public ResultSetExecution createResultSetExecution(QueryExpression query, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
Properties groupProps = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
groupProps.setProperty("customName", "CustomTableA");
NamedTable group = (NamedTable) query.getProjectedQuery().getFrom().get(0);
AbstractMetadataRecord groupMD = group.getMetadataObject();
TestCase.assertEquals(groupProps, groupMD.getProperties());
DerivedColumn symbl = query.getProjectedQuery().getDerivedColumns().get(0);
ColumnReference element = (ColumnReference) symbl.getExpression();
Column elementMD = element.getMetadataObject();
Properties elementProps = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
elementProps.setProperty("customPosition", "11");
TestCase.assertEquals(0, elementMD.getLength());
// $NON-NLS-1$
TestCase.assertEquals("Foo", elementMD.getDefaultValue());
// $NON-NLS-1$
TestCase.assertEquals("TrimNulls", elementMD.getFormat());
TestCase.assertEquals(String.class, elementMD.getJavaType());
TestCase.assertEquals(null, elementMD.getMaximumValue());
TestCase.assertEquals(null, elementMD.getMinimumValue());
// $NON-NLS-1$
TestCase.assertEquals("COLUMN1", elementMD.getNameInSource());
// $NON-NLS-1$
TestCase.assertEquals("STR", elementMD.getNativeType());
TestCase.assertEquals(NullType.Nullable, elementMD.getNullType());
TestCase.assertEquals(0, elementMD.getPosition());
TestCase.assertEquals(0, elementMD.getPrecision());
TestCase.assertEquals(0, elementMD.getScale());
TestCase.assertEquals(SearchType.Searchable, elementMD.getSearchType());
TestCase.assertEquals(false, elementMD.isAutoIncremented());
TestCase.assertEquals(true, elementMD.isCaseSensitive());
TestCase.assertEquals(elementProps, elementMD.getProperties());
DerivedColumn symbl2 = query.getProjectedQuery().getDerivedColumns().get(1);
ColumnReference element2 = (ColumnReference) symbl2.getExpression();
Column elementMD2 = element2.getMetadataObject();
Properties elementProps2 = new Properties();
// $NON-NLS-1$ //$NON-NLS-2$
elementProps2.setProperty("customPosition", "12");
TestCase.assertEquals(10, elementMD2.getLength());
// $NON-NLS-1$
TestCase.assertEquals("23", elementMD2.getDefaultValue());
// $NON-NLS-1$
TestCase.assertEquals("YesFormat", elementMD2.getFormat());
TestCase.assertEquals(Integer.class, elementMD2.getJavaType());
// $NON-NLS-1$
TestCase.assertEquals("1", elementMD2.getMaximumValue());
// $NON-NLS-1$
TestCase.assertEquals("100", elementMD2.getMinimumValue());
// $NON-NLS-1$
TestCase.assertEquals("COLUMN2", elementMD2.getNameInSource());
// $NON-NLS-1$
TestCase.assertEquals("INT", elementMD2.getNativeType());
TestCase.assertEquals(NullType.No_Nulls, elementMD2.getNullType());
TestCase.assertEquals(1, elementMD2.getPosition());
TestCase.assertEquals(0, elementMD2.getPrecision());
TestCase.assertEquals(10, elementMD2.getScale());
TestCase.assertEquals(SearchType.Searchable, elementMD2.getSearchType());
TestCase.assertEquals(true, elementMD2.isAutoIncremented());
TestCase.assertEquals(false, elementMD2.isCaseSensitive());
TestCase.assertEquals(elementProps2, elementMD2.getProperties());
ResultSetExecution exec = Mockito.mock(ResultSetExecution.class);
Mockito.stub(exec.next()).toReturn(null);
return exec;
}
use of org.teiid.language.ColumnReference in project teiid by teiid.
the class TestElement method getElement.
public Column getElement(String groupName, String elementName, TranslationUtility transUtil) throws Exception {
// $NON-NLS-1$ //$NON-NLS-2$
Select query = (Select) transUtil.parseCommand("SELECT " + elementName + " FROM " + groupName);
DerivedColumn symbol = query.getDerivedColumns().get(0);
ColumnReference element = (ColumnReference) symbol.getExpression();
return element.getMetadataObject();
}
Aggregations