use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class LanguageBridgeFactory method translate.
org.teiid.language.Comparison translate(DependentSetCriteria criteria) {
Operator operator = Operator.EQ;
org.teiid.language.Expression arg = null;
final TupleBuffer tb = criteria.getDependentValueSource().getTupleBuffer();
if (criteria.getValueExpression() instanceof Array) {
Array array = (Array) criteria.getValueExpression();
List<org.teiid.language.Expression> params = new ArrayList<org.teiid.language.Expression>();
Class<?> baseType = null;
for (Expression ex : array.getExpressions()) {
if (baseType == null) {
baseType = ex.getType();
} else if (!baseType.equals(ex.getType())) {
baseType = DataTypeManager.DefaultDataClasses.OBJECT;
}
params.add(createParameter(criteria, tb, ex));
}
arg = new org.teiid.language.Array(baseType, params);
} else {
Expression ex = criteria.getValueExpression();
arg = createParameter(criteria, tb, ex);
}
if (this.dependentSets == null) {
this.dependentSets = new HashMap<String, List<? extends List<?>>>();
}
this.dependentSets.put(criteria.getContextSymbol(), new TupleBufferList(tb));
Comparison result = new org.teiid.language.Comparison(translate(criteria.getExpression()), arg, operator);
return result;
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestProcessor method doProcess.
public static long doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
BufferManager bufferMgr = context.getBufferManager();
if (bufferMgr == null) {
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setProcessorBatchSize(context.getProcessorBatchSize());
context.setBufferManager(bm);
bufferMgr = bm;
}
context.getNextRand(0);
if (context.getTempTableStore() == null) {
context.setTempTableStore(new TempTableStore(context.getConnectionId(), TransactionMode.ISOLATE_WRITES));
}
if (context.getGlobalTableStore() == null) {
GlobalTableStoreImpl gts = new GlobalTableStoreImpl(bufferMgr, null, context.getMetadata());
context.setGlobalTableStore(gts);
}
if (!(dataManager instanceof TempTableDataManager)) {
SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
cache.setTupleBufferCache(bufferMgr);
dataManager = new TempTableDataManager(dataManager, bufferMgr, cache);
}
if (context.getQueryProcessorFactory() == null) {
context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
}
TupleBuffer id = null;
long rowCount = 0;
try {
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
// processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
for (int i = 0; i < 100; i++) {
try {
id = collector.collectTuples();
break;
} catch (BlockedException e) {
}
}
if (id == null) {
fail("did not complete processing");
}
rowCount = id.getRowCount();
if (DEBUG) {
// $NON-NLS-1$
System.out.println("\nResults:\n" + id.getSchema());
TupleSource ts2 = id.createIndexedTupleSource();
for (int j = 0; j < rowCount; j++) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("" + j + ": " + ts2.nextTuple());
}
}
if (expectedResults != null) {
examineResults(expectedResults, bufferMgr, id);
}
} finally {
if (id != null) {
id.remove();
}
}
return rowCount;
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestProcessor method helpProcessException.
private void helpProcessException(ProcessorPlan plan, ProcessorDataManager dataManager, String expectedErrorMessage) {
TupleBuffer tsId = null;
BufferManager bufferMgr = null;
try {
bufferMgr = BufferManagerFactory.getStandaloneBufferManager();
// $NON-NLS-1$ //$NON-NLS-2$
CommandContext context = new CommandContext("0", "test", null, null, 1);
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
tsId = collector.collectTuples();
// $NON-NLS-1$
fail("Expected error during processing, but got none.");
} catch (TeiidException e) {
// ignore - this is expected
if (expectedErrorMessage != null) {
assertEquals(expectedErrorMessage, e.getMessage());
}
} finally {
if (tsId != null) {
tsId.remove();
}
}
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class TestVirtualDepJoin method helpTestMultipleBatches.
private void helpTestMultipleBatches(boolean unique) throws Exception, TeiidComponentException, TeiidException, SQLException {
// Create query
// $NON-NLS-1$
String sql = "SELECT * from Master.Transactions where last = 'Davis' order by CustomerID, TransactionID";
List<List<Object>> expected = new LinkedList<List<Object>>();
// Create expected results
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }));
if (!unique) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(123), new Integer(1), new BigDecimal("100.00") }));
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }));
if (!unique) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(127), new Integer(2), new BigDecimal("250.00") }));
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }));
if (!unique) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15000), new Long(128), new Integer(3), new BigDecimal("1000.00") }));
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }));
if (!unique) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(134), new Integer(1), new BigDecimal("10.00") }));
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }));
if (!unique) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(15001), new Long(201), new Integer(1), new BigDecimal("10.00") }));
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }));
if (!unique) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1002), new Integer(1), new BigDecimal("7.20") }));
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }));
if (!unique) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(100), "Miles", "Davis", new Long(540), new Long(1003), new Integer(2), new BigDecimal("1000.00") }));
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(207), new Integer(3), new BigDecimal("12.34") }));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(16000), new Long(299), new Integer(3), new BigDecimal("950.34") }));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1004), new Integer(3), new BigDecimal("542.20") }));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(200), "CloneA", "Davis", new Long(550), new Long(1005), new Integer(1), new BigDecimal("99.99") }));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1006), new Integer(1), new BigDecimal("10000.00") }));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(620), new Long(1007), new Integer(2), new BigDecimal("0.75") }));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
expected.add(Arrays.asList(new Object[] { new Long(300), "CloneB", "Davis", new Long(630), new Long(1008), new Integer(2), new BigDecimal("62.00") }));
// Construct data manager with data
QueryMetadataInterface metadata = exampleVirtualDepJoin();
FakeDataManager dataManager = new FakeDataManager();
sampleDataVirtualDepJoin(dataManager, metadata);
overrideVirtualDepJoinData(dataManager, metadata, unique);
// Plan query
CommandContext context = TestProcessor.createCommandContext();
Command command = TestProcessor.helpParse(sql);
FakeCapabilitiesFinder finder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
// $NON-NLS-1$
finder.addCapabilities("US", caps);
// $NON-NLS-1$
finder.addCapabilities("Europe", caps);
// $NON-NLS-1$
finder.addCapabilities("CustomerMaster", caps);
ProcessorPlan plan = TestProcessor.helpGetPlan(command, metadata, finder, context);
// Run query
BufferManager bufferMgr = createCustomBufferMgr(2);
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
TupleBuffer id = collector.collectTuples();
TestProcessor.examineResults(expected.toArray(new List[expected.size()]), bufferMgr, id);
}
use of org.teiid.common.buffer.TupleBuffer in project teiid by teiid.
the class FakeRelationalNode method getBufferDirect.
@Override
protected TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
TupleBuffer tb = Mockito.mock(TupleBuffer.class);
Mockito.stub(tb.getRowCount()).toReturn((long) (maxRows != -1 ? Math.min(maxRows, data.length) : data.length));
return tb;
}
Aggregations