Search in sources :

Example 1 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.

the class QueryGuessCommandTest method generateNewQuery.

@Test
public void generateNewQuery() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    connection = ConnectionFactory.eINSTANCE.createConnection();
    node = Mockito.mock(INode.class);
    connection.setContextMode(true);
    TdTable table = RelationalFactory.eINSTANCE.createTdTable();
    table.setName("tableName");
    table.setLabel("tableLabel");
    TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
    column1.setId("ID1");
    column1.setName("cName1");
    TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
    column2.setId("ID2");
    column2.setName("cName2");
    table.getColumns().add(column1);
    table.getColumns().add(column2);
    metadataTable = ConvertionHelper.convert(table);
    ElementParameter parameter = new ElementParameter(node);
    parameter.setName("DBTABLE");
    parameter.setValue(table.getName());
    Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
    Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
    String schema = "schema";
    // add test for PostgreSQL
    String dbType = EDatabaseTypeName.PSQL.getDisplayName();
    QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
    Method method = command.getClass().getDeclaredMethod("generateNewQuery");
    method.setAccessible(true);
    String queryString = (String) method.invoke(command);
    Assert.assertNotNull(queryString);
    Assert.assertTrue(queryString.contains(schema));
    Assert.assertTrue(queryString.contains(metadataTable.getTableName()));
    Assert.assertTrue(queryString.contains("cName1"));
    Assert.assertTrue(queryString.contains("cName2"));
    // add test for MySQL
    dbType = EDatabaseTypeName.MYSQL.getDisplayName();
    command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
    method = command.getClass().getDeclaredMethod("generateNewQuery");
    method.setAccessible(true);
    queryString = (String) method.invoke(command);
    Assert.assertNotNull(queryString);
    Assert.assertFalse(queryString.contains(schema));
    Assert.assertTrue(queryString.contains(metadataTable.getTableName()));
    Assert.assertTrue(queryString.contains("cName1"));
    Assert.assertTrue(queryString.contains("cName2"));
}
Also used : INode(org.talend.core.model.process.INode) ElementParameter(org.talend.designer.core.model.components.ElementParameter) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.

the class QueryGuessCommandTest method generateNewTeradataQuery.

@Test
public void generateNewTeradataQuery() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PersistenceException {
    connection = ConnectionFactory.eINSTANCE.createConnection();
    node = Mockito.mock(INode.class);
    connection.setContextMode(true);
    TdTable table = RelationalFactory.eINSTANCE.createTdTable();
    table.setName("tableName");
    table.setLabel("tableLabel");
    TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
    column1.setName("id");
    TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
    column2.setName("name");
    table.getColumns().add(column1);
    table.getColumns().add(column2);
    metadataTable = ConvertionHelper.convert(table);
    ElementParameter parameter = new ElementParameter(node);
    parameter.setName("DBTABLE");
    parameter.setValue(table.getName());
    Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
    Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
    // test case 1
    String schema = "myschema";
    String dbType = EDatabaseTypeName.TERADATA.getDisplayName();
    String expectedQuery = "\"SELECT myschema.tableName.\\\"id\\\", myschema.tableName.name FROM myschema.tableName\"";
    QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
    Method method = command.getClass().getDeclaredMethod("generateNewQuery");
    method.setAccessible(true);
    String queryString = (String) method.invoke(command);
    Assert.assertEquals(expectedQuery, queryString);
}
Also used : INode(org.talend.core.model.process.INode) ElementParameter(org.talend.designer.core.model.components.ElementParameter) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 3 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdi-studio-se by Talend.

the class MetadataColumnComparator method saveEMFMetadataColumn.

@SuppressWarnings("unchecked")
private static void saveEMFMetadataColumn(String id, List<MetadataColumn> columnNodes) {
    DatabaseConnectionItem item = getEMFItem(id);
    final DatabaseConnection connection = (DatabaseConnection) item.getConnection();
    IMetadataConnection iMetadataConnection = ConvertionHelper.convert(connection);
    Set<MetadataTable> tableset = ConnectionHelper.getTables(connection);
    List<MetadataTable> tables = new ArrayList<MetadataTable>();
    tables.addAll(tableset);
    List<MetadataColumn> emfCols = new ArrayList<MetadataColumn>();
    List<MetadataColumn> dbCols = new ArrayList<MetadataColumn>();
    for (MetadataColumn col : columnNodes) {
        for (MetadataTable table : tables) {
            if (table.getLabel().equals(col.getTable().getLabel())) {
                List<TdColumn> returnCols = ExtractMetaDataFromDataBase.returnMetadataColumnsFormTable(iMetadataConnection, table.getSourceName());
                for (MetadataColumn emfcolumn : table.getColumns()) {
                    for (MetadataColumn column : returnCols) {
                        if (emfcolumn.getLabel().equals(col.getLabel()) && column.getLabel().equals(col.getOriginalField())) {
                            emfCols.add(emfcolumn);
                            dbCols.add(column);
                        }
                    }
                }
            }
        }
    }
    saveOneMetadataColumn(emfCols, columnNodes, dbCols);
    saveMetaData(item);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdColumn(org.talend.cwm.relational.TdColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 4 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.

the class FunctionalDependencyAnalysisDetailsPage method getColumnSet.

private List<RepositoryNode> getColumnSet(EReference reference) {
    List<RepositoryNode> columns = new ArrayList<RepositoryNode>();
    EList<Indicator> indicators = getCurrentModelElement().getResults().getIndicators();
    for (Indicator indicator : indicators) {
        TdColumn findColumn = (TdColumn) indicator.eGet(reference);
        RepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(findColumn);
        if (recursiveFind == null) {
            recursiveFind = RepositoryNodeHelper.createRepositoryNode(findColumn);
        }
        if (recursiveFind != null) {
            columns.add(recursiveFind);
        }
    }
    return columns;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Indicator(org.talend.dataquality.indicators.Indicator) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)

Example 5 with TdColumn

use of org.talend.cwm.relational.TdColumn in project tdq-studio-se by Talend.

the class FunctionalDependencyAnalysisDetailsPage method validator.

private ReturnCode validator(List<RepositoryNode> columnASet, List<RepositoryNode> columnBSet) {
    // MOD by gdbu 2011-3-21 bug 19179
    ReturnCode canModRetCode = super.canSave();
    if (!canModRetCode.isOk()) {
        return canModRetCode;
    }
    if (columnASet.isEmpty() || columnBSet.isEmpty()) {
        // $NON-NLS-1$
        return new ReturnCode(DefaultMessagesImpl.getString("ColumnDependencyMasterDetailsPage.columnsBlankMessag"), false);
    }
    if (columnASet.size() != columnBSet.size()) {
        // $NON-NLS-1$
        return new ReturnCode(DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.columnsSameMessage"), false);
    }
    for (int i = 0; i < columnASet.size(); i++) {
        RepositoryNode columnANode = columnASet.get(i);
        RepositoryNode columnBNode = columnBSet.get(i);
        TdColumn tdColumnA = ((DBColumnRepNode) columnANode).getTdColumn();
        TdColumn tdColumnB = ((DBColumnRepNode) columnBNode).getTdColumn();
        ColumnSet ownerA = ColumnHelper.getColumnOwnerAsColumnSet(tdColumnA);
        ColumnSet ownerB = ColumnHelper.getColumnOwnerAsColumnSet(tdColumnB);
        String uuidA = ResourceHelper.getUUID(ownerA);
        String uuidB = ResourceHelper.getUUID(ownerB);
        if (!uuidA.equals(uuidB)) {
            // $NON-NLS-1$
            return new ReturnCode(DefaultMessagesImpl.getString("ColumnDependencyMasterDetailsPage.tableMessage"), false);
        }
    }
    return new ReturnCode(true);
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) TdColumn(org.talend.cwm.relational.TdColumn) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) DBColumnRepNode(org.talend.dq.nodes.DBColumnRepNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Aggregations

TdColumn (org.talend.cwm.relational.TdColumn)182 ArrayList (java.util.ArrayList)49 TdTable (org.talend.cwm.relational.TdTable)49 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)40 Test (org.junit.Test)37 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)35 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)28 RepositoryNode (org.talend.repository.model.RepositoryNode)26 IRepositoryNode (org.talend.repository.model.IRepositoryNode)23 Indicator (org.talend.dataquality.indicators.Indicator)20 Catalog (orgomg.cwm.resource.relational.Catalog)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)16 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)16 Analysis (org.talend.dataquality.analysis.Analysis)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)14 Package (orgomg.cwm.objectmodel.core.Package)14 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)13