use of org.talend.dataquality.indicators.schema.CatalogIndicator in project tdq-studio-se by Talend.
the class OverviewResultPage method createResultSection.
@Override
protected void createResultSection(Composite parent) {
statisticalSection = this.createSection(form, parent, DefaultMessagesImpl.getString("ConnectionMasterDetailsPage.statisticalinformations"), // $NON-NLS-1$
null);
Composite sectionClient = toolkit.createComposite(statisticalSection);
sectionClient.setLayout(new GridLayout());
catalogTableViewer = new TableViewer(sectionClient, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
Table catalogTable = catalogTableViewer.getTable();
TableUtils.addActionTooltip(catalogTable);
catalogTable.setHeaderVisible(true);
catalogTable.setBackgroundMode(SWT.INHERIT_FORCE);
catalogTable.setLinesVisible(true);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(catalogTable);
List<Catalog> catalogs = getCatalogs();
boolean containSubSchema = false;
for (Catalog catalog : catalogs) {
List<Schema> schemas = CatalogHelper.getSchemas(catalog);
if (schemas.size() > 0) {
containSubSchema = true;
break;
}
}
if (catalogs.size() > 0 && containSubSchema) {
createCatalogSchemaColumns(catalogTable);
provider = new CatalogSchemaViewerProvier();
addColumnSorters(catalogTableViewer, catalogTable.getColumns(), catalogWithSchemaSorters);
createSchemaTableViewer(sectionClient);
schemaTableViewer.addSelectionChangedListener(new DisplayTableAndViewListener());
catalogTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
StructuredSelection selection = (StructuredSelection) event.getSelection();
OverviewIndUIElement firstElement = (OverviewIndUIElement) selection.getFirstElement();
List<OverviewIndUIElement> cataUIEleList = new ArrayList<OverviewIndUIElement>();
if (firstElement != null) {
Indicator overviewIndicator = firstElement.getOverviewIndicator();
// selection.getFirstElement();
CatalogIndicator catalogIndicator = (CatalogIndicator) overviewIndicator;
// MOD qiongli bug 13093,2010-7-2,
// selection.getFirstElement();
currentCatalogIndicator = (SchemaIndicator) overviewIndicator;
// MOD xqliu 2009-11-30 bug 9114
if (catalogIndicator != null) {
EList<SchemaIndicator> schemaIndicators = catalogIndicator.getSchemaIndicators();
for (SchemaIndicator schemaIndicator : schemaIndicators) {
RepositoryNode schemaNode = RepositoryNodeHelper.recursiveFind(schemaIndicator.getAnalyzedElement());
OverviewIndUIElement cataUIEle = new OverviewIndUIElement();
cataUIEle.setNode(schemaNode);
cataUIEle.setOverviewIndicator(schemaIndicator);
cataUIEleList.add(cataUIEle);
}
schemaTableViewer.setInput(cataUIEleList);
schemaTableViewer.getTable().setVisible(true);
addColumnSorters(schemaTableViewer, schemaTableViewer.getTable().getColumns(), schemaSorters);
}
}
// ~
}
});
createContextMenuFor(schemaTableViewer);
} else {
if (catalogs.size() > 0) {
createCatalogTableColumns(catalogTable);
provider = new CatalogViewerProvier();
} else {
createSchemaTableColumns(catalogTable);
provider = new SchemaViewerProvier();
}
addColumnSorters(catalogTableViewer, catalogTable.getColumns(), schemaSorters);
catalogTableViewer.addSelectionChangedListener(new DisplayTableAndViewListener());
}
catalogTableViewer.setLabelProvider(provider);
catalogTableViewer.setContentProvider(provider);
doSetInput();
tableAndViewComposite = new Composite(sectionClient, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableAndViewComposite);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
layout.horizontalSpacing = 50;
tableAndViewComposite.setLayout(layout);
tableAndViewComposite.setVisible(false);
sectionClient.layout();
statisticalSection.setClient(sectionClient);
createContextMenuFor(catalogTableViewer);
}
use of org.talend.dataquality.indicators.schema.CatalogIndicator in project tdq-studio-se by Talend.
the class CatalogEvaluator method executeSqlQuery.
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
ReturnCode ok = new ReturnCode(true);
// --- preconditions
DataProvider dataProvider = this.getDataManager();
if (this.elementToIndicators.values().isEmpty()) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator1");
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
Indicator[] indics = this.getAllIndicators();
if (indics.length == 0) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator2", dataProvider);
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
for (Indicator indicator : indics) {
CatalogIndicator catalogIndicator = DataqualitySwitchHelper.CATALOG_SWITCH.doSwitch(indicator);
if (catalogIndicator == null) {
continue;
}
Catalog catalog = (Catalog) catalogIndicator.getAnalyzedElement();
String catName = catalog.getName();
// MOD yyi 2009-11-30 10187
if (!checkCatalog(catName)) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.catalogNotExist", catName), false);
return ok;
}
// MOD qiongli 2012-8-9,Method 'Method not supported' not supported for HiveConnection
if (dbms().supportCatalogSelection()) {
connection.setCatalog(catName);
}
List<Schema> schemas = CatalogHelper.getSchemas(catalog);
if (schemas.isEmpty()) {
// no schema
evalCatalogIndic(catalogIndicator, catalog, ok);
} else {
catalogIndicator.setAnalyzedElement(catalog);
catalogIndicator.setSchemaCount(schemas.size());
// --- create SchemaIndicator for each pair of catalog schema
for (Schema tdSchema : schemas) {
// --- create SchemaIndicator for each catalog
SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
evalSchemaIndicLow(catalogIndicator, schemaIndic, catalog, tdSchema, ok);
}
}
}
return ok;
}
use of org.talend.dataquality.indicators.schema.CatalogIndicator in project tdq-studio-se by Talend.
the class ConnectionEvaluator method addToConnectionIndicator.
@Override
protected void addToConnectionIndicator(Indicator indicator) {
final ConnectionIndicator connectionIndicator = getConnectionIndicator();
if (connectionIndicator == null) {
return;
}
SchemaSwitch<Boolean> schemaSwitch = new SchemaSwitch<Boolean>() {
/*
* (non-Javadoc)
*
* @see
* org.talend.dataquality.indicators.schema.util.SchemaSwitch#caseCatalogIndicator(org.talend.dataquality
* .indicators.schema.CatalogIndicator)
*/
@Override
public Boolean caseCatalogIndicator(CatalogIndicator object) {
connectionIndicator.addCatalogIndicator(object);
connectionIndicator.setCatalogCount(connectionIndicator.getCatalogCount() + 1);
// increment schema count
connectionIndicator.setSchemaCount(connectionIndicator.getSchemaCount() + object.getSchemaCount());
// MOD scorreia 2009-01-16 increment other counts
incrementCounts(connectionIndicator, object);
return true;
}
private void incrementCounts(final ConnectionIndicator connIndicator, SchemaIndicator childIndicator) {
connIndicator.setTableCount(connIndicator.getTableCount() + childIndicator.getTableCount());
connIndicator.setTableRowCount(connIndicator.getTableRowCount() + childIndicator.getTableRowCount());
// MOD klliu 2011-12-26 bug TDQ-4235
connIndicator.setViewCount(connIndicator.getViewCount() + childIndicator.getViewCount());
connIndicator.setViewRowCount(connIndicator.getViewRowCount() + childIndicator.getViewRowCount());
connIndicator.setKeyCount(connIndicator.getKeyCount() + childIndicator.getKeyCount());
connIndicator.setIndexCount(connIndicator.getIndexCount() + childIndicator.getIndexCount());
}
/*
* (non-Javadoc)
*
* @see
* org.talend.dataquality.indicators.schema.util.SchemaSwitch#caseSchemaIndicator(org.talend.dataquality
* .indicators.schema.SchemaIndicator)
*/
@Override
public Boolean caseSchemaIndicator(SchemaIndicator object) {
connectionIndicator.addSchemaIndicator(object);
connectionIndicator.setSchemaCount(connectionIndicator.getSchemaCount() + 1);
// MOD scorreia 2009-01-16 increment other counts
incrementCounts(connectionIndicator, object);
return true;
}
};
schemaSwitch.doSwitch(indicator);
}
use of org.talend.dataquality.indicators.schema.CatalogIndicator in project tdq-studio-se by Talend.
the class ConnectionEvaluator method executeSqlQuery.
/*
* (non-Javadoc)
*
* @see org.talend.dq.indicators.Evaluator#executeSqlQuery(java.lang.String)
*
* Note that the given statement is not used.
*/
@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
// assert this.getAnalyzedElements().size() == 1 : "Invalid number of analyzed elements: "
// + this.getAnalyzedElements().size();
ReturnCode ok = new ReturnCode(true);
dataProvider = this.getDataManager();
if (this.elementToIndicators.values().isEmpty()) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator1");
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
elementIndics = this.elementToIndicators.values().iterator().next();
if (elementIndics.isEmpty()) {
// $NON-NLS-1$
String msg = Messages.getString("Evaluator.NoInidcator2", dataProvider);
log.error(msg);
ok.setReturnCode(msg, false);
return ok;
}
ConnectionIndicator connectionIndicator = getConnectionIndicator();
this.resetCounts(connectionIndicator);
List<Catalog> catalogs = ConnectionHelper.getCatalogs(dataProvider);
if (isTos(dataProvider)) {
cleanUpCatalog(catalogs);
}
if (this.getMonitor() != null) {
this.getMonitor().beginTask("Analyze catalogs", 100);
}
int temp = 0;
if (catalogs.isEmpty()) {
// no catalog, only schemata
List<Schema> schemata = ConnectionHelper.getSchema(dataProvider);
// MOD yyi 2009-11-30 10187
for (Schema tdSchema : schemata) {
if (!checkSchema(tdSchema)) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.schemaNotExist", tdSchema.getName()), false);
return ok;
}
}
// for (Schema tdSchema : schemata) {
for (int i = 0; i < schemata.size(); i++) {
Schema tdSchema = schemata.get(i);
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
}
evalSchemaIndic(tdSchema, ok);
if (this.getMonitor() != null) {
int current = (i + 1) * 100 / schemata.size();
if (current > temp) {
this.getMonitor().worked(current - temp);
temp = current;
}
}
}
} else {
// MOD yyi 2009-11-30 10187
for (Catalog tdCatalog : catalogs) {
if (!checkCatalog(tdCatalog.getName())) {
// $NON-NLS-1$
ok.setReturnCode(Messages.getString("Evaluator.catalogNotExist", tdCatalog.getName()), false);
return ok;
}
}
// for (Catalog tdCatalog : catalogs) {
for (int i = 0; i < catalogs.size(); i++) {
if (this.continueRun()) {
Catalog tdCatalog = catalogs.get(i);
String catName = tdCatalog.getName();
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName)));
}
if (dbms().supportCatalogSelection()) {
try {
connection.setCatalog(catName);
} catch (SQLException e) {
// $NON-NLS-1$
log.warn("Exception while executing SQL query " + sqlStatement, e);
}
}
CatalogIndicator catalogIndic = SchemaFactory.eINSTANCE.createCatalogIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(catalogIndic);
List<Schema> schemas = CatalogHelper.getSchemas(tdCatalog);
if (schemas.isEmpty()) {
// no schema
evalCatalogIndic(catalogIndic, tdCatalog, ok);
} else {
catalogIndic.setAnalyzedElement(tdCatalog);
// --- create SchemaIndicator for each pair of catalog schema
for (Schema tdSchema : schemas) {
if (this.continueRun()) {
if (this.getMonitor() != null) {
this.getMonitor().setTaskName(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName) + ", " + Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", tdSchema.getName())));
}
// --- create SchemaIndicator for each catalog
SchemaIndicator schemaIndic = SchemaFactory.eINSTANCE.createSchemaIndicator();
// MOD xqliu 2009-1-21 feature 4715
DefinitionHandler.getInstance().setDefaultIndicatorDefinition(schemaIndic);
evalSchemaIndicLow(catalogIndic, schemaIndic, tdCatalog, tdSchema, ok);
}
}
catalogIndic.setSchemaCount(schemas.size());
}
if (this.getMonitor() != null) {
int current = (i + 1) * 100 / catalogs.size();
if (current > temp) {
this.getMonitor().worked(current - temp);
temp = current;
}
}
}
}
if (this.getMonitor() != null) {
this.getMonitor().done();
}
}
if (log.isDebugEnabled()) {
printCounts(connectionIndicator);
}
return ok;
}
use of org.talend.dataquality.indicators.schema.CatalogIndicator in project tdq-studio-se by Talend.
the class CatalogWithSchemaSorter method compare.
public int compare(Viewer viewer, Object o1, Object o2) {
CatalogIndicator indicator1 = (CatalogIndicator) ((OverviewIndUIElement) o1).getOverviewIndicator();
CatalogIndicator indicator2 = (CatalogIndicator) ((OverviewIndUIElement) o2).getOverviewIndicator();
String value1;
String value2;
long number1;
long number2;
switch(sortType) {
case CATALOG:
value1 = indicator1.getAnalyzedElement().getName();
value2 = indicator2.getAnalyzedElement().getName();
return value1.compareTo(value2);
case -CATALOG:
value1 = indicator1.getAnalyzedElement().getName();
value2 = indicator2.getAnalyzedElement().getName();
return value2.compareTo(value1);
case ROWS:
number1 = indicator1.getTableRowCount();
number2 = indicator2.getTableRowCount();
return new Long(number1).compareTo(new Long(number2));
case -ROWS:
number1 = indicator1.getTableRowCount();
number2 = indicator2.getTableRowCount();
return new Long(number2).compareTo(new Long(number1));
case SCHEMAS:
number1 = indicator1.getSchemaCount();
number2 = indicator2.getSchemaCount();
return new Long(number1).compareTo(new Long(number2));
case -SCHEMAS:
number1 = indicator1.getSchemaCount();
number2 = indicator2.getSchemaCount();
return new Long(number2).compareTo(new Long(number1));
case ROWS_SCHEMAS:
number1 = indicator1.getSchemaCount() == 0 ? 0 : indicator1.getTableRowCount() / indicator1.getSchemaCount();
number2 = indicator2.getSchemaCount() == 0 ? 0 : indicator2.getTableRowCount() / indicator2.getSchemaCount();
return new Long(number1).compareTo(new Long(number2));
case -ROWS_SCHEMAS:
number1 = indicator1.getSchemaCount() == 0 ? 0 : indicator1.getTableRowCount() / indicator1.getSchemaCount();
number2 = indicator2.getSchemaCount() == 0 ? 0 : indicator2.getTableRowCount() / indicator2.getSchemaCount();
return new Long(number2).compareTo(new Long(number1));
case TABLES:
number1 = indicator1.getTableCount();
number2 = indicator2.getTableCount();
return new Long(number1).compareTo(new Long(number2));
case -TABLES:
number1 = indicator1.getTableCount();
number2 = indicator2.getTableCount();
return new Long(number2).compareTo(new Long(number1));
case ROWS_TABLES:
number1 = indicator1.getTableCount() == 0 ? 0 : indicator1.getTableRowCount() / indicator1.getTableCount();
number2 = indicator2.getTableCount() == 0 ? 0 : indicator2.getTableRowCount() / indicator2.getTableCount();
return new Long(number1).compareTo(new Long(number2));
case -ROWS_TABLES:
number1 = indicator1.getTableCount() == 0 ? 0 : indicator1.getTableRowCount() / indicator1.getTableCount();
number2 = indicator2.getTableCount() == 0 ? 0 : indicator2.getTableRowCount() / indicator2.getTableCount();
return new Long(number2).compareTo(new Long(number1));
case VIEWS:
number1 = indicator1.getViewCount();
number2 = indicator2.getViewCount();
return new Long(number1).compareTo(new Long(number2));
case -VIEWS:
number1 = indicator1.getViewCount();
number2 = indicator2.getViewCount();
return new Long(number2).compareTo(new Long(number1));
case ROWS_VIEWS:
number1 = indicator1.getViewCount() == 0 ? 0 : indicator1.getTableRowCount() / indicator1.getViewCount();
number2 = indicator2.getViewCount() == 0 ? 0 : indicator2.getTableRowCount() / indicator2.getViewCount();
return new Long(number1).compareTo(new Long(number2));
case -ROWS_VIEWS:
number1 = indicator1.getViewCount() == 0 ? 0 : indicator1.getTableRowCount() / indicator1.getViewCount();
number2 = indicator2.getViewCount() == 0 ? 0 : indicator2.getTableRowCount() / indicator2.getViewCount();
return new Long(number2).compareTo(new Long(number1));
case KEYS:
number1 = indicator1.getKeyCount();
number2 = indicator2.getKeyCount();
return new Long(number1).compareTo(new Long(number2));
case -KEYS:
number1 = indicator1.getKeyCount();
number2 = indicator2.getKeyCount();
return new Long(number2).compareTo(new Long(number1));
case INDEXES:
number1 = indicator1.getIndexCount();
number2 = indicator2.getIndexCount();
return new Long(number1).compareTo(new Long(number2));
case -INDEXES:
number1 = indicator1.getIndexCount();
number2 = indicator2.getIndexCount();
return new Long(number2).compareTo(new Long(number1));
default:
return 0;
}
}
Aggregations