Search in sources :

Example 1 with DateGrain

use of org.talend.dataquality.indicators.DateGrain in project tdq-studio-se by Talend.

the class TimeSlicesForm method addFields.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataprofiler.core.ui.utils.AbstractForm#addFields()
     */
@Override
protected void addFields() {
    this.setLayout(new GridLayout());
    Group group = new Group(this, SWT.NONE);
    group.setLayout(new GridLayout(DateGrain.VALUES.size() / 2, true));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // $NON-NLS-1$
    group.setText(DefaultMessagesImpl.getString("TimeSlicesForm.AggregatedateBy"));
    for (DateGrain oneDate : DateGrain.VALUES) {
        btn = new Button(group, SWT.RADIO);
        btn.setText(oneDate.getLiteral());
        allBtns.add(btn);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) DateGrain(org.talend.dataquality.indicators.DateGrain) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData)

Example 2 with DateGrain

use of org.talend.dataquality.indicators.DateGrain in project tdq-studio-se by Talend.

the class DateParametersImpl method setDateAggregationType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setDateAggregationType(DateGrain newDateAggregationType) {
    DateGrain oldDateAggregationType = dateAggregationType;
    dateAggregationType = newDateAggregationType == null ? DATE_AGGREGATION_TYPE_EDEFAULT : newDateAggregationType;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, IndicatorsPackage.DATE_PARAMETERS__DATE_AGGREGATION_TYPE, oldDateAggregationType, dateAggregationType));
}
Also used : DateGrain(org.talend.dataquality.indicators.DateGrain) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 3 with DateGrain

use of org.talend.dataquality.indicators.DateGrain in project tdq-studio-se by Talend.

the class FrequencyIndicatorImpl method storeSqlResults.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dataquality.indicators.impl.IndicatorImpl#storeSqlResults(java.lang.Object[])
     * 
     * ADDED scorreia 2008-04-30 storeSqlResults(List<Object[]> objects)
     */
@SuppressWarnings("fallthrough")
@Override
public boolean storeSqlResults(List<Object[]> objects) {
    // handle case when frequencies are computed on dates.
    int nbColumns = 2;
    if (hasDateGrainParameter()) {
        DateGrain dategrain = getParameters().getDateParameters().getDateAggregationType();
        switch(dategrain) {
            case DAY:
                nbColumns++;
            // no break
            case WEEK:
                nbColumns++;
            // no break
            case MONTH:
                nbColumns++;
            // no break
            case QUARTER:
                nbColumns++;
            // no break
            case YEAR:
                break;
            default:
                break;
        }
    }
    // handle case when no row is returned because there is no value.
    if (objects.isEmpty()) {
        if (log.isInfoEnabled()) {
            log.info("Query for frequency table did not return any result. " + "Check the options of this indicator. Bins must contains some data.");
        }
        this.setValueToFreq(new HashMap<Object, Long>());
        return true;
    }
    // else we got some values
    if (!checkResults(objects, nbColumns)) {
        return false;
    }
    HashMap<Object, Long> mapVal2Freq = new HashMap<Object, Long>();
    boolean debug = log.isDebugEnabled();
    StringBuffer matrix = debug ? new StringBuffer() : null;
    for (Object[] value2freq : objects) {
        if (value2freq.length != nbColumns) {
            log.error("Problem with result for Frequency indicator");
            return false;
        }
        Object value = getValueFields(value2freq);
        // MOD gdbu 2011-4-14 bug : 18975
        // Long freq = Long.valueOf(String.valueOf(value2freq[nbColumns - 1]));
        Long freq = IndicatorHelper.getLongFromObject(value2freq[nbColumns - 1]);
        // ~18975
        mapVal2Freq.put(value, freq);
        if (debug) {
            matrix.append("\n").append("\"").append(value).append("\"").append(",").append(freq);
        }
    }
    if (debug) {
        log.debug(matrix);
    }
    this.setValueToFreq(mapVal2Freq);
    return true;
}
Also used : DateGrain(org.talend.dataquality.indicators.DateGrain) HashMap(java.util.HashMap)

Example 4 with DateGrain

use of org.talend.dataquality.indicators.DateGrain in project tdq-studio-se by Talend.

the class ColumnAnalysisSqlExecutor method createSqlQuery.

/**
 * Method "createSqlQuery".
 *
 * @param dataFilterExpression
 * @param analysis
 * @param indicator
 *
 * @throws ParseException
 * @throws AnalysisExecutionException
 */
private boolean createSqlQuery(String dataFilterAsString, Indicator indicator) throws AnalysisExecutionException {
    TypedReturnCode<TdColumn> checkResult = getTdColumn(indicator);
    if (!checkResult.isOk()) {
        return false;
    }
    TdColumn tdColumn = checkResult.getObject();
    if (tdColumn.eIsProxy()) {
        tdColumn = (TdColumn) EObjectHelper.resolveObject(tdColumn);
    }
    TypedReturnCode<String> columnName = getColumnName(indicator, tdColumn);
    if (!columnName.isOk()) {
        return false;
    }
    String colName = columnName.getObject();
    TypedReturnCode<IndicatorDefinition> id = getIndicatorDefinition(indicator);
    if (!id.isOk()) {
        return false;
    }
    IndicatorDefinition indicatorDefinition = id.getObject();
    // get correct language for current database
    String language = dbms().getDbmsName();
    // --- create select statement
    // get indicator's sql columnS (generate the real SQL statement from its definition)
    Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
    final EClass indicatorEclass = indicator.eClass();
    if (sqlGenericExpression == null || sqlGenericExpression.getBody() == null) {
        // analysis, will not check the sql expression and create again(from the definition).
        if (UDIHelper.isUDI(indicator) && indicator.getInstantiatedExpressions().size() > 0) {
            return Boolean.TRUE;
        }
        // expressions.
        if (IndicatorsPackage.eINSTANCE.getRegexpMatchingIndicator().equals(indicatorEclass)) {
            // $NON-NLS-1$
            traceError(Messages.getString("ColumnAnalysisSqlExecutor.PLEASEREMOVEALLPATTEN"));
            return Boolean.FALSE;
        }
        traceError(Messages.getString(// $NON-NLS-1$
        "ColumnAnalysisSqlExecutor.UNSUPPORTEDINDICATOR", (indicator.getName() != null ? AnalysisExecutorHelper.getIndicatorName(indicator) : indicatorEclass.getName())));
        return Boolean.FALSE;
    }
    // --- get indicator parameters and convert them into sql expression
    List<String> whereExpression = new ArrayList<String>();
    if (StringUtils.isNotBlank(dataFilterAsString)) {
        whereExpression.add(dataFilterAsString);
    }
    List<String> rangeStrings = null;
    DateGrain dateAggregationType = null;
    IndicatorParameters parameters = indicator.getParameters();
    if (parameters != null) {
        // handle bins
        Domain bins = parameters.getBins();
        if (bins != null) {
            rangeStrings = getBinsAsGenericString(bins.getRanges(), colName);
        }
        DateParameters dateParameters = parameters.getDateParameters();
        if (dateParameters != null) {
            dateAggregationType = dateParameters.getDateAggregationType();
        }
        TextParameters textParameter = parameters.getTextParameter();
        if (textParameter != null) {
            if (textParameter.isIgnoreCase()) {
                colName = dbms().toUpperCase(colName);
            }
            if (!textParameter.isUseBlank() && IndicatorsPackage.eINSTANCE.getLengthIndicator().isSuperTypeOf(indicatorEclass)) {
                String tdColName = getQuotedColumnName(tdColumn);
                // $NON-NLS-1$
                tdColName = dbms().replaceNullsWithString(tdColName, "'NULL TALEND'");
            } else if (textParameter.isUseBlank() && IndicatorsPackage.eINSTANCE.getFrequencyIndicator().isSuperTypeOf(indicatorEclass)) {
                colName = dbms().trim(colName);
            }
        }
    }
    TypedReturnCode<String> completedQuery = getCompletedQuery(indicator, tdColumn, colName, indicatorDefinition, language, sqlGenericExpression, indicatorEclass, whereExpression, rangeStrings, dateAggregationType);
    if (!completedQuery.isOk()) {
        return false;
    }
    String finalQuery = completedQuery.getObject();
    if (finalQuery != null) {
        TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(language, finalQuery);
        indicator.setInstantiatedExpression(instantiateSqlExpression);
        return true;
    }
    return false;
}
Also used : DateGrain(org.talend.dataquality.indicators.DateGrain) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) DateParameters(org.talend.dataquality.indicators.DateParameters) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) TextParameters(org.talend.dataquality.indicators.TextParameters) EClass(org.eclipse.emf.ecore.EClass) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Domain(org.talend.dataquality.domain.Domain)

Example 5 with DateGrain

use of org.talend.dataquality.indicators.DateGrain in project tdq-studio-se by Talend.

the class FrequencyStatisticsExplorer method getFreqRowsStatement.

protected String getFreqRowsStatement() {
    IndicatorDefinition indicatorDefinition = this.indicator.getIndicatorDefinition();
    if (indicatorDefinition instanceof UDIndicatorDefinition) {
        return getQueryForUDIndicator(indicatorDefinition);
    }
    String clause = PluginConstant.EMPTY_STRING;
    TdColumn column = (TdColumn) indicator.getAnalyzedElement();
    int javaType = column.getSqlDataType().getJavaDataType();
    if (Java2SqlType.isTextInSQL(javaType)) {
        clause = getInstantiatedClause();
    } else if (Java2SqlType.isDateInSQL(javaType)) {
        // MOD scorreia 2009-09-22 first check whether the value is null
        if (entity.isLabelNull()) {
            clause = getInstantiatedClause();
        } else {
            IndicatorParameters parameters = indicator.getParameters();
            if (parameters != null) {
                DateParameters dateParameters = parameters.getDateParameters();
                if (dateParameters != null) {
                    DateGrain dateGrain = dateParameters.getDateAggregationType();
                    clause = entity.isLabelNull() ? getInstantiatedClause() : getClauseWithDate(dateGrain, clause);
                } else {
                    clause = getInstantiatedClause();
                }
            } else {
                clause = getInstantiatedClause();
            }
        }
    } else if (Java2SqlType.isNumbericInSQL(javaType)) {
        IndicatorParameters parameters = indicator.getParameters();
        if (parameters != null) {
            // handle bins
            Domain bins = parameters.getBins();
            if (bins != null) {
                // rangeStrings = getBinsAsGenericString(bins.getRanges());
                final EList<RangeRestriction> ranges = bins.getRanges();
                for (RangeRestriction rangeRestriction : ranges) {
                    // find the rangeLabel
                    if (entity.getLabel() != null && entity.getLabel().equals(rangeRestriction.getName())) {
                        clause = createWhereClause(rangeRestriction);
                        break;
                    }
                }
            } else {
                // MOD hcheng 2009-05-18.Bug 7377,Frequency indicator,when bins is null,handle as textual data
                clause = getInstantiatedClause();
            }
        } else {
            // MOD scorreia 2009-05-13. Bug 7235
            // no parameter set: handle as textual data
            clause = getInstantiatedClause();
        }
    } else {
        // no quote here
        clause = getDefaultQuotedStatement(PluginConstant.EMPTY_STRING);
    }
    return // $NON-NLS-1$
    "SELECT * FROM " + getFullyQualifiedTableName(column) + dbmsLanguage.where() + inBrackets(clause) + andDataFilterClause();
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) DateGrain(org.talend.dataquality.indicators.DateGrain) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) DateParameters(org.talend.dataquality.indicators.DateParameters) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Aggregations

DateGrain (org.talend.dataquality.indicators.DateGrain)7 DateParameters (org.talend.dataquality.indicators.DateParameters)3 HashMap (java.util.HashMap)2 TdColumn (org.talend.cwm.relational.TdColumn)2 Domain (org.talend.dataquality.domain.Domain)2 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)2 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)2 ArrayList (java.util.ArrayList)1 EClass (org.eclipse.emf.ecore.EClass)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Group (org.eclipse.swt.widgets.Group)1 TdExpression (org.talend.cwm.relational.TdExpression)1 RangeRestriction (org.talend.dataquality.domain.RangeRestriction)1 TextParameters (org.talend.dataquality.indicators.TextParameters)1 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)1 Expression (orgomg.cwm.objectmodel.core.Expression)1