Search in sources :

Example 1 with MetadataResult

use of org.teiid.client.metadata.MetadataResult in project teiid by teiid.

the class TestMetaDataProcessor method testDefect16629_moneyType.

@Test
public void testDefect16629_moneyType() throws Exception {
    QueryMetadataInterface metadata = TestMetaDataProcessor.examplePrivatePhysicalModel();
    // $NON-NLS-1$
    String sql = "SELECT e1 FROM pm1.g2";
    MetadataResult response = helpTestQuery(metadata, sql, TestMetaDataProcessor.examplePrivatePhysicalModelVDB());
    helpCheckNumericAttributes(response, 0, 21, 19, 4);
}
Also used : QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) MetadataResult(org.teiid.client.metadata.MetadataResult) Test(org.junit.Test)

Example 2 with MetadataResult

use of org.teiid.client.metadata.MetadataResult in project teiid by teiid.

the class TestMetaDataProcessor method testArrayAgg.

@Test
public void testArrayAgg() throws Exception {
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    // $NON-NLS-1$
    String sql = "SELECT array_agg(e1) FROM pm1.g2";
    MetadataResult response = helpTestQuery(metadata, sql, RealMetadataFactory.example1VDB());
    assertEquals("string[]", response.getColumnMetadata()[0].get(ResultsMetadataConstants.DATA_TYPE));
}
Also used : QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) MetadataResult(org.teiid.client.metadata.MetadataResult) Test(org.junit.Test)

Example 3 with MetadataResult

use of org.teiid.client.metadata.MetadataResult in project teiid by teiid.

the class TestMetaDataProcessor method testWindowFunction.

@Test
public void testWindowFunction() throws Exception {
    QueryMetadataInterface metadata = TestMetaDataProcessor.examplePrivatePhysicalModel();
    // $NON-NLS-1$
    String sql = "SELECT min(e1) over () FROM pm1.g2";
    MetadataResult response = helpTestQuery(metadata, sql, TestMetaDataProcessor.examplePrivatePhysicalModelVDB());
    helpCheckNumericAttributes(response, 0, 21, 19, 4);
    // $NON-NLS-1$
    assertEquals("e1", response.getColumnMetadata()[0].get(ResultsMetadataConstants.ELEMENT_NAME));
    // $NON-NLS-1$
    assertEquals("expr1", response.getColumnMetadata()[0].get(ResultsMetadataConstants.ELEMENT_LABEL));
}
Also used : QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) MetadataResult(org.teiid.client.metadata.MetadataResult) Test(org.junit.Test)

Example 4 with MetadataResult

use of org.teiid.client.metadata.MetadataResult in project teiid by teiid.

the class MetaDataProcessor method getMetadataForCommand.

// For each projected symbol, construct a metadata map
private MetadataResult getMetadataForCommand(Command originalCommand) throws TeiidComponentException {
    Map<Integer, Object>[] columnMetadata = null;
    switch(originalCommand.getType()) {
        case Command.TYPE_QUERY:
            if (originalCommand instanceof Query) {
                if (((Query) originalCommand).getInto() == null) {
                    columnMetadata = createProjectedSymbolMetadata(originalCommand);
                }
            } else {
                columnMetadata = createProjectedSymbolMetadata(originalCommand);
            }
            break;
        case Command.TYPE_STORED_PROCEDURE:
            columnMetadata = createProjectedSymbolMetadata(originalCommand);
            break;
        case Command.TYPE_INSERT:
        case Command.TYPE_UPDATE:
        case Command.TYPE_DELETE:
        case Command.TYPE_CREATE:
        case Command.TYPE_DROP:
            break;
        default:
            if (originalCommand.returnsResultSet()) {
                columnMetadata = createProjectedSymbolMetadata(originalCommand);
            }
    }
    Map<Reference, String> paramMap = Collections.emptyMap();
    if (originalCommand instanceof StoredProcedure) {
        StoredProcedure sp = (StoredProcedure) originalCommand;
        paramMap = new HashMap<Reference, String>();
        Collection<SPParameter> params = sp.getParameters();
        for (SPParameter spParameter : params) {
            if (spParameter.getParameterType() != SPParameter.INOUT && spParameter.getParameterType() != SPParameter.IN && spParameter.getParameterType() != SPParameter.RETURN_VALUE) {
                continue;
            }
            Expression ex = spParameter.getExpression();
            if (ex instanceof Function && FunctionLibrary.isConvert((Function) ex)) {
                ex = ((Function) ex).getArg(0);
            }
            if (ex instanceof Reference) {
                paramMap.put((Reference) ex, spParameter.getParameterSymbol().getShortName());
            }
        }
    }
    List<Reference> params = ReferenceCollectorVisitor.getReferences(originalCommand);
    Map<Integer, Object>[] paramMetadata = new Map[params.size()];
    for (int i = 0; i < params.size(); i++) {
        Reference param = params.get(i);
        paramMetadata[i] = getDefaultColumn(null, paramMap.get(param), param.getType());
    }
    return new MetadataResult(columnMetadata, paramMetadata);
}
Also used : Query(org.teiid.query.sql.lang.Query) Reference(org.teiid.query.sql.symbol.Reference) SPParameter(org.teiid.query.sql.lang.SPParameter) MetadataResult(org.teiid.client.metadata.MetadataResult) Function(org.teiid.query.sql.symbol.Function) WindowFunction(org.teiid.query.sql.symbol.WindowFunction) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Expression(org.teiid.query.sql.symbol.Expression) HashMap(java.util.HashMap) Map(java.util.Map) SymbolMap(org.teiid.query.sql.util.SymbolMap)

Example 5 with MetadataResult

use of org.teiid.client.metadata.MetadataResult in project teiid by teiid.

the class TestMetaDataProcessor method testDefect16629_aggregatesOnMoneyType.

@Test
public void testDefect16629_aggregatesOnMoneyType() throws Exception {
    QueryMetadataInterface metadata = TestMetaDataProcessor.examplePrivatePhysicalModel();
    // $NON-NLS-1$
    String sql = "SELECT min(e1), max(e1), sum(e1), avg(e1) FROM pm1.g2";
    MetadataResult response = helpTestQuery(metadata, sql, TestMetaDataProcessor.examplePrivatePhysicalModelVDB());
    helpCheckNumericAttributes(response, 0, 21, 19, 4);
    helpCheckNumericAttributes(response, 1, 21, 19, 4);
    helpCheckNumericAttributes(response, 2, 22, 20, 0);
    helpCheckNumericAttributes(response, 3, 22, 20, 0);
}
Also used : QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) MetadataResult(org.teiid.client.metadata.MetadataResult) Test(org.junit.Test)

Aggregations

MetadataResult (org.teiid.client.metadata.MetadataResult)6 Test (org.junit.Test)4 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TeiidComponentException (org.teiid.core.TeiidComponentException)1 TeiidProcessingException (org.teiid.core.TeiidProcessingException)1 Query (org.teiid.query.sql.lang.Query)1 SPParameter (org.teiid.query.sql.lang.SPParameter)1 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)1 Expression (org.teiid.query.sql.symbol.Expression)1 Function (org.teiid.query.sql.symbol.Function)1 Reference (org.teiid.query.sql.symbol.Reference)1 WindowFunction (org.teiid.query.sql.symbol.WindowFunction)1 SymbolMap (org.teiid.query.sql.util.SymbolMap)1