Search in sources :

Example 1 with AggregateFunction

use of org.teiid.language.AggregateFunction in project teiid by teiid.

the class CoherenceVisitor method getExpressionString.

// GHH 20080326 - found that code to fall back on Name if NameInSource
// was null wasn't working properly, so replaced with tried and true
// code from another custom connector.
private String getExpressionString(Expression e) throws TranslatorException {
    String expressionName = null;
    // - the rest of this method is unchanged
    if (e instanceof ColumnReference) {
        Column mdIDElement = ((ColumnReference) e).getMetadataObject();
        expressionName = mdIDElement.getNameInSource();
        if (expressionName == null || expressionName.equals("")) {
            // $NON-NLS-1$
            expressionName = mdIDElement.getName();
        }
    } else if (e instanceof Literal) {
        // try {
        // if(((Literal)e).getType().equals(Class.forName(Timestamp.class.getName()))) {
        // LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Found an expression that uses timestamp; converting to LDAP string format."); //$NON-NLS-1$
        // Timestamp ts = (Timestamp)((Literal)e).getValue();
        // Date dt = new Date(ts.getTime());
        // //TODO: Fetch format if provided.
        // SimpleDateFormat sdf = new SimpleDateFormat(LDAPConnectorConstants.ldapTimestampFormat);
        // expressionName = sdf.format(dt);
        // LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Timestamp to stsring is: " + expressionName); //$NON-NLS-1$
        // }
        // else {
        // expressionName = ((Literal)e).getValue().toString();
        // }
        expressionName = ((Literal) e).getValue().toString();
    // } catch (ClassNotFoundException cce) {
    // final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.timestampClassNotFoundError"); //$NON-NLS-1$
    // throw new TranslatorException(cce, msg);
    // }
    // 
    } else {
        if (e instanceof AggregateFunction) {
            // $NON-NLS-1$
            LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IAggregate, but it is not supported. Check capabilities.");
        } else if (e instanceof Function) {
            // $NON-NLS-1$
            LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IFunction, but it is not supported. Check capabilties.");
        } else if (e instanceof ScalarSubquery) {
            // $NON-NLS-1$
            LogManager.logError(LogConstants.CTX_CONNECTOR, "Received IScalarSubquery, but it is not supported. Check capabilties.");
        } else if (e instanceof SearchedCase) {
            // $NON-NLS-1$
            LogManager.logError(LogConstants.CTX_CONNECTOR, "Received ISearchedCaseExpression, but it is not supported. Check capabilties.");
        }
        // $NON-NLS-1$
        final String msg = CoherencePlugin.Util.getString("CoherenceVisitory.unsupportedElementError", e.toString());
        throw new TranslatorException(msg);
    }
    expressionName = escapeReservedChars(expressionName);
    return expressionName;
}
Also used : SearchedCase(org.teiid.language.SearchedCase) Function(org.teiid.language.Function) AggregateFunction(org.teiid.language.AggregateFunction) ScalarSubquery(org.teiid.language.ScalarSubquery) Column(org.teiid.metadata.Column) DerivedColumn(org.teiid.language.DerivedColumn) Literal(org.teiid.language.Literal) AggregateFunction(org.teiid.language.AggregateFunction) TranslatorException(org.teiid.translator.TranslatorException) ColumnReference(org.teiid.language.ColumnReference)

Example 2 with AggregateFunction

use of org.teiid.language.AggregateFunction in project teiid by teiid.

the class TestAggregateImpl method testGetExpression.

public void testGetExpression() throws Exception {
    // $NON-NLS-1$
    AggregateFunction agg = example("testName", NonReserved.COUNT, true, 42);
    assertNotNull(agg.getExpression());
    assertTrue(agg.getExpression() instanceof Literal);
    assertEquals(new Integer(42), ((Literal) agg.getExpression()).getValue());
}
Also used : AggregateFunction(org.teiid.language.AggregateFunction) Literal(org.teiid.language.Literal)

Aggregations

AggregateFunction (org.teiid.language.AggregateFunction)2 Literal (org.teiid.language.Literal)2 ColumnReference (org.teiid.language.ColumnReference)1 DerivedColumn (org.teiid.language.DerivedColumn)1 Function (org.teiid.language.Function)1 ScalarSubquery (org.teiid.language.ScalarSubquery)1 SearchedCase (org.teiid.language.SearchedCase)1 Column (org.teiid.metadata.Column)1 TranslatorException (org.teiid.translator.TranslatorException)1