use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class TempTableStore method addForeignTempTable.
void addForeignTempTable(final String tempTableName, Create create) {
TempMetadataID id = tempMetadataStore.getTempGroupID(tempTableName);
if (id == null) {
id = tempMetadataStore.addTempGroup(tempTableName, create.getColumnSymbols(), false, true);
id.setOriginalMetadataID(create.getTableMetadata());
id.getTableData().setModel(create.getTableMetadata().getParent());
}
this.foreignTempTables.put(tempTableName, create.getTableMetadata());
}
use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class GlobalTableStoreImpl method resolveIndex.
static ArrayList<TempMetadataID> resolveIndex(QueryMetadataInterface metadata, TempMetadataID id, Object pk) throws TeiidComponentException, QueryMetadataException {
List cols = metadata.getElementIDsInKey(pk);
ArrayList<TempMetadataID> primaryKey = new ArrayList<TempMetadataID>(cols.size());
for (Object coldId : cols) {
int pos = metadata.getPosition(coldId) - 1;
primaryKey.add(id.getElements().get(pos));
}
return primaryKey;
}
use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class TempTable method insert.
public TupleSource insert(TupleSource tuples, final List<ElementSymbol> variables, boolean canUndo, boolean upsert, CommandContext context) throws TeiidComponentException, ExpressionEvaluationException, TeiidProcessingException {
List<ElementSymbol> cols = getColumns();
final int[] indexes = new int[cols.size()];
boolean shouldProject = false;
for (int i = 0; i < cols.size(); i++) {
indexes[i] = variables.indexOf(cols.get(i));
shouldProject |= (indexes[i] != i);
}
InsertUpdateProcessor up = new InsertUpdateProcessor(tuples, rowId != null, shouldProject ? indexes : null, canUndo, upsert);
if (context != null && context.isReturnAutoGeneratedKeys() && rowId == null) {
List<String> colNames = null;
List<Class<?>> colTypes = null;
for (int i = 0; i < tree.getKeyLength(); i++) {
TempMetadataID col = tid.getElements().get(i);
if (col.isAutoIncrement() && indexes[i] == -1) {
if (colNames == null) {
colNames = new ArrayList<String>();
colTypes = new ArrayList<Class<?>>();
}
colNames.add(col.getName());
colTypes.add(col.getType());
break;
}
}
if (colNames != null) {
GeneratedKeysImpl keys = context.returnGeneratedKeys(colNames.toArray(new String[colNames.size()]), colTypes.toArray(new Class<?>[colTypes.size()]));
up.setGeneratedKeys(keys);
}
}
long updateCount = up.process();
tid.setCardinality(tree.getRowCount());
tid.getTableData().dataModified(updateCount);
return CollectionTupleSource.createUpdateCountArrayTupleSource(updateCount);
}
use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class TestMultiSourceMetadataWrapper method testMultiSourcePseudoElement.
@Test
public void testMultiSourcePseudoElement() throws Exception {
HashSet<String> multiSourceModels = new HashSet<String>();
multiSourceModels.add("BQT1");
MultiSourceMetadataWrapper wrapper = new MultiSourceMetadataWrapper(RealMetadataFactory.exampleBQTCached(), multiSourceModels);
// $NON-NLS-1$
Object groupID = wrapper.getGroupID("BQT1.SmallA");
List<?> elements = wrapper.getElementIDsInGroupID(groupID);
assertEquals(18, elements.size());
Object instanceElementID = elements.get(elements.size() - 1);
String fullName = wrapper.getFullName(instanceElementID);
// $NON-NLS-1$
assertEquals("BQT1.SmallA." + MultiSourceElement.DEFAULT_MULTI_SOURCE_ELEMENT_NAME, fullName);
assertEquals(instanceElementID, wrapper.getElementID(fullName));
assertEquals(groupID, wrapper.getGroupIDForElementID(instanceElementID));
assertEquals(null, wrapper.getMaximumValue(instanceElementID));
assertEquals(null, wrapper.getMinimumValue(instanceElementID));
assertEquals(wrapper.getModelID(groupID), wrapper.getModelID(instanceElementID));
assertEquals(null, wrapper.getDefaultValue(instanceElementID));
assertEquals(255, wrapper.getElementLength(instanceElementID));
assertEquals(DataTypeManager.DefaultDataTypes.STRING, wrapper.getElementRuntimeTypeName(instanceElementID));
assertEquals(new Properties(), wrapper.getExtensionProperties(instanceElementID));
assertEquals(null, wrapper.getNameInSource(instanceElementID));
assertEquals(null, wrapper.getNativeType(instanceElementID));
assertEquals(18, wrapper.getPosition(instanceElementID));
assertEquals(0, wrapper.getPrecision(instanceElementID));
assertEquals(0, wrapper.getScale(instanceElementID));
assertEquals(0, wrapper.getRadix(instanceElementID));
assertEquals(MultiSourceElement.DEFAULT_MULTI_SOURCE_ELEMENT_NAME, Symbol.getShortName(fullName));
assertEquals(fullName, wrapper.getFullName(groupID) + Symbol.SEPARATOR + MultiSourceElement.DEFAULT_MULTI_SOURCE_ELEMENT_NAME);
TempMetadataAdapter tma = new TempMetadataAdapter(wrapper, new TempMetadataStore());
ElementSymbol elementSymbol = new ElementSymbol("y");
elementSymbol.setType(DataTypeManager.DefaultDataClasses.STRING);
TempMetadataID id = tma.getMetadataStore().addTempGroup("x", Arrays.asList(elementSymbol));
assertFalse(tma.isMultiSourceElement(id.getElements().get(0)));
assertTrue(tma.isMultiSourceElement(instanceElementID));
assertTrue(tma.isPseudo(instanceElementID));
assertEquals(17, tma.getElementIDsInGroupID(tma.getGroupID("VQT.Smalla")).size());
}
use of org.teiid.query.metadata.TempMetadataID in project teiid by teiid.
the class TestProcedurePlanner method helpPlanProcedure.
// ################ getReplacementClause tests ###################
private ProcessorPlan helpPlanProcedure(String userQuery, String procedure, TriggerEvent procedureType) throws TeiidComponentException, QueryMetadataException, TeiidProcessingException {
QueryMetadataInterface metadata = RealMetadataFactory.exampleUpdateProc(procedureType, procedure);
QueryParser parser = QueryParser.getQueryParser();
Command userCommand = userQuery != null ? parser.parseCommand(userQuery) : parser.parseCommand(procedure);
if (userCommand instanceof CreateProcedureCommand) {
GroupSymbol gs = new GroupSymbol("proc");
gs.setMetadataID(new TempMetadataID("proc", Collections.EMPTY_LIST));
((CreateProcedureCommand) userCommand).setVirtualGroup(gs);
}
QueryResolver.resolveCommand(userCommand, metadata);
ValidatorReport report = Validator.validate(userCommand, metadata);
if (report.hasItems()) {
ValidatorFailure firstFailure = report.getItems().iterator().next();
throw new QueryValidatorException(firstFailure.getMessage());
}
userCommand = QueryRewriter.rewrite(userCommand, metadata, null);
AnalysisRecord analysisRecord = new AnalysisRecord(false, DEBUG);
try {
return QueryOptimizer.optimizePlan(userCommand, metadata, null, new DefaultCapabilitiesFinder(), analysisRecord, null);
} finally {
if (DEBUG) {
System.out.println(analysisRecord.getDebugLog());
}
}
}
Aggregations