use of org.teiid.metadata.AbstractMetadataRecord in project teiid by teiid.
the class AccumuloQueryVisitor method visit.
@Override
public void visit(Select obj) {
visitNodes(obj.getFrom());
visitNodes(obj.getDerivedColumns());
visitNode(obj.getWhere());
visitNode(obj.getGroupBy());
visitNode(obj.getHaving());
visitNode(obj.getOrderBy());
visitNode(obj.getLimit());
if (this.doScanEvaluation) {
HashMap<String, String> options = buildEvaluatorOptions(this.scanTable);
SQLStringVisitor visitor = new SQLStringVisitor() {
@Override
public String getName(AbstractMetadataRecord object) {
return object.getName();
}
};
visitor.append(obj.getWhere());
options.put(EvaluatorIterator.QUERYSTRING, visitor.toString());
IteratorSetting it = new IteratorSetting(1, EvaluatorIterator.class, options);
this.scanIterators.add(it);
}
}
use of org.teiid.metadata.AbstractMetadataRecord in project teiid by teiid.
the class QueryExecutionImpl method extractValuesFromElement.
// TODO: this looks inefficient as getChild is linear
private List<Object[]> extractValuesFromElement(XmlObject sObject, List<Object[]> result, String sObjectName) throws TranslatorException {
Object[] row = new Object[visitor.getSelectSymbolCount()];
for (int j = 0; j < visitor.getSelectSymbolCount(); j++) {
// must be a column reference as we won't allow an agg over a join
Column element = ((ColumnReference) visitor.getSelectSymbolMetadata(j)).getMetadataObject();
AbstractMetadataRecord table = element.getParent();
if (table.getSourceName().equals(sObjectName)) {
XmlObject child = sObject.getChild(element.getSourceName());
Object cell = getCellDatum(element.getSourceName(), element.getJavaType(), child);
setElementValueInColumn(j, cell, row);
}
}
result.add(row);
return result;
}
use of org.teiid.metadata.AbstractMetadataRecord 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.metadata.AbstractMetadataRecord in project teiid by teiid.
the class TestTranslationUtility method testGetRMD.
public void testGetRMD() throws Exception {
TranslationUtility util = new TranslationUtility(getTestVDB());
// Translate command to get some ids
// $NON-NLS-1$
Select query = (Select) util.parseCommand("select * from partssupplier.parts");
NamedTable group = (NamedTable) query.getFrom().get(0);
AbstractMetadataRecord mid = group.getMetadataObject();
// $NON-NLS-1$
assertEquals("PartsSupplier.PARTSSUPPLIER.PARTS", mid.getFullName());
// Use RMD to get stuff
// $NON-NLS-1$
assertEquals("PARTS", mid.getNameInSource());
}
use of org.teiid.metadata.AbstractMetadataRecord 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;
}
Aggregations