Search in sources :

Example 41 with TempMetadataID

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());
}
Also used : TempMetadataID(org.teiid.query.metadata.TempMetadataID)

Example 42 with TempMetadataID

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;
}
Also used : TempMetadataID(org.teiid.query.metadata.TempMetadataID) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ReplicatedObject(org.teiid.query.ReplicatedObject) CacheHint(org.teiid.query.sql.lang.CacheHint)

Example 43 with TempMetadataID

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);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) GeneratedKeysImpl(org.teiid.query.util.GeneratedKeysImpl) CacheHint(org.teiid.query.sql.lang.CacheHint)

Example 44 with TempMetadataID

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());
}
Also used : TempMetadataAdapter(org.teiid.query.metadata.TempMetadataAdapter) ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) Properties(java.util.Properties) TempMetadataStore(org.teiid.query.metadata.TempMetadataStore) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 45 with TempMetadataID

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());
        }
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) AnalysisRecord(org.teiid.query.analysis.AnalysisRecord) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) CreateProcedureCommand(org.teiid.query.sql.proc.CreateProcedureCommand) Command(org.teiid.query.sql.lang.Command) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) QueryValidatorException(org.teiid.api.exception.query.QueryValidatorException) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TempMetadataID(org.teiid.query.metadata.TempMetadataID) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Aggregations

TempMetadataID (org.teiid.query.metadata.TempMetadataID)48 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)21 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)16 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)12 QueryMetadataException (org.teiid.api.exception.query.QueryMetadataException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Test (org.junit.Test)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6 CreateProcedureCommand (org.teiid.query.sql.proc.CreateProcedureCommand)6 HashSet (java.util.HashSet)5 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)5 TeiidComponentException (org.teiid.core.TeiidComponentException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)5 LanguageObject (org.teiid.query.sql.LanguageObject)4 CacheHint (org.teiid.query.sql.lang.CacheHint)4 Expression (org.teiid.query.sql.symbol.Expression)4 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)3 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)3