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);
}
}
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));
}
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;
}
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;
}
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();
}
Aggregations