Search in sources :

Example 81 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.

the class Neo4jMetadataProvider method addMetadataColumn.

private void addMetadataColumn(String columnName, String columnType, String returnParam, List<MetadataColumn> metadataColumns, List<String> columnLabels) {
    MetadataColumn metaColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
    metaColumn.setName(columnName);
    metaColumn.setLabel(columnName);
    metaColumn.setTalendType(columnType);
    EList<TaggedValue> keyTaggedValue = metaColumn.getTaggedValue();
    TaggedValue keyTV = CoreFactory.eINSTANCE.createTaggedValue();
    keyTV.setTag(INeo4jConstants.RETURN_PARAMETER);
    keyTV.setValue(returnParam);
    keyTaggedValue.add(keyTV);
    metadataColumns.add(metaColumn);
    columnLabels.add(metaColumn.getLabel());
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue)

Example 82 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.

the class CassandraMetadataProvider method extractColumns.

/*
     * (non-Javadoc)
     *
     * @see
     * org.talend.repository.nosql.metadata.AbstractMetadataProvider#extractColumns(org.talend.repository.model.nosql
     * .NoSQLConnection, java.lang.String)
     */
@Override
public List<MetadataColumn> extractColumns(NoSQLConnection connection, String tableName) throws NoSQLExtractSchemaException {
    List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
    if (connection == null || tableName == null) {
        return metadataColumns;
    }
    try {
        String dbName = NoSQLSchemaUtil.getSchemaNameByTableLabel(connection, tableName);
        metadataColumns.addAll(extractTheColumns(connection, dbName, tableName));
    } catch (Exception e) {
        throw new NoSQLExtractSchemaException(e);
    }
    return metadataColumns;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ArrayList(java.util.ArrayList) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)

Example 83 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.

the class HCatalogRepositoryContentHandler method createPartitionColumns.

private void createPartitionColumns(RepositoryNode tableNode, IRepositoryViewObject repObj, MetadataTable metadataTable) {
    List<MetadataColumn> partitionColumns = new ArrayList<MetadataColumn>();
    EMap<String, String> properties = metadataTable.getAdditionalProperties();
    String partitionStr = properties.get(HCatalogConstants.PARTITIONS);
    if (partitionStr != null) {
        partitionColumns = ExtractMetaDataFromHCatalog.extractPartitionsByJsonStr(partitionStr);
    }
    int num = partitionColumns.size();
    StringBuffer floderName = new StringBuffer();
    // $NON-NLS-1$
    floderName.append(Messages.getString("HCatalogRepositoryContentHandler.partitions"));
    // $NON-NLS-1$
    floderName.append("(");
    floderName.append(num);
    // $NON-NLS-1$
    floderName.append(")");
    RepositoryNode columnsNode = new StableRepositoryNode(tableNode, floderName.toString(), ECoreImage.FOLDER_CLOSE_ICON);
    tableNode.getChildren().add(columnsNode);
    for (MetadataColumn column : partitionColumns) {
        if (column == null) {
            continue;
        }
        RepositoryNode columnNode = RepositoryNodeManager.createMataColumnNode(columnsNode, repObj, column);
        columnsNode.getChildren().add(columnNode);
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) StableRepositoryNode(org.talend.repository.model.StableRepositoryNode) ArrayList(java.util.ArrayList) StableRepositoryNode(org.talend.repository.model.StableRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode)

Example 84 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.

the class HCatalogSchemaForm method pressRetreiveSchemaButton.

private void pressRetreiveSchemaButton() {
    ConnectionStatus connectionStatus = checkConnection(false);
    if (!connectionStatus.getResult()) {
        tableSettingsInfoLabel.setText(connectionStatus.getMessageException());
    } else {
        boolean doit = true;
        if (tableEditorView.getMetadataEditor().getBeanCount() > 0) {
            doit = // $NON-NLS-1$
            MessageDialog.openConfirm(// $NON-NLS-1$
            getShell(), // $NON-NLS-1$
            Messages.getString("HCatalogSchemaForm.title.confirmChange"), // $NON-NLS-1$
            Messages.getString("HCatalogSchemaForm.msg.changeSchema"));
        }
        if (doit) {
            String tableName = metadataTable.getName();
            List<MetadataColumn> metadataColumns = null;
            List<MetadataColumn> partitionColumns = null;
            String partitionJsonStr = null;
            try {
                metadataColumns = ExtractMetaDataFromHCatalog.extractColumns(getConnection(), tableName);
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return;
            }
            try {
                partitionColumns = ExtractMetaDataFromHCatalog.extractPartitions(getConnection(), tableName);
                partitionJsonStr = ExtractMetaDataFromHCatalog.extractPartitionsJsonStr(getConnection(), tableName);
            } catch (Exception e) {
                // $NON-NLS-1$
                log.warn(Messages.getString("HCatalogTableSelectorForm.cannotExtractPartitionsWarn", tableName), e);
            }
            Map<String, MetadataColumn> partitionColumnsMap = new HashMap<String, MetadataColumn>();
            if (partitionColumns != null && partitionColumns.size() > 0) {
                for (MetadataColumn column : partitionColumns) {
                    partitionColumnsMap.put(column.getLabel(), column);
                }
            }
            Iterator<MetadataColumn> columnIterator = metadataColumns.iterator();
            while (columnIterator.hasNext()) {
                MetadataColumn column = columnIterator.next();
                if (partitionColumnsMap.get(column.getLabel()) != null) {
                    columnIterator.remove();
                }
            }
            tableEditorView.getMetadataEditor().removeAll();
            tableEditorView.getMetadataEditor().addAll(metadataColumns);
            if (partitionJsonStr != null) {
                EMap<String, String> properties = metadataTable.getAdditionalProperties();
                properties.put(HCatalogConstants.PARTITIONS, partitionJsonStr);
            }
        }
    }
    updateRetreiveSchemaButton();
    changeTableNavigatorStatus(checkFieldsValue());
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) HashMap(java.util.HashMap) ConnectionStatus(org.talend.core.repository.model.connection.ConnectionStatus)

Example 85 with MetadataColumn

use of org.talend.core.model.metadata.builder.connection.MetadataColumn in project tbd-studio-se by Talend.

the class Neo4jMetadataProviderTest method testLocalRetrieveSchema.

@Test
public void testLocalRetrieveSchema() throws Exception {
    EMap<String, String> attributes = localConnection.getAttributes();
    // $NON-NLS-1$
    attributes.put(INeo4jAttributes.REMOTE_SERVER, "false");
    attributes.put(INeo4jAttributes.DATABASE_PATH, tmpFolder.getCanonicalPath());
    attributes.put(INeo4jAttributes.DB_VERSION, INeo4jConstants.NEO4J_3_2_X);
    localConnection.setDbType("NEO4J");
    ExecutorService threadExecutor = null;
    try {
        threadExecutor = Executors.newSingleThreadExecutor();
        Future future = threadExecutor.submit(new Runnable() {

            public void run() {
                try {
                    Neo4jConnectionUtil.checkConnection(localConnection);
                    List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
                    String cypher = "create (n:Test {first_name : 'Peppa', last_name : 'Pig'})\r\nreturn n;";
                    IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(localConnection.getDbType());
                    metadataColumns = metadataProvider.extractColumns(localConnection, cypher);
                    String lastName = metadataColumns.get(0).getName();
                    assertEquals("last_name", lastName);
                    String firstName = metadataColumns.get(1).getName();
                    assertEquals("first_name", firstName);
                } catch (Exception e) {
                    fail(e.getMessage());
                }
            }
        });
        while (true) {
            if (future.get() == null) {
                break;
            }
            Thread.sleep(1000);
        }
    } catch (Exception exception) {
        fail(exception.getMessage());
    } finally {
        if (threadExecutor != null) {
            threadExecutor.shutdown();
            threadExecutor = null;
        }
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) IMetadataProvider(org.talend.repository.nosql.metadata.IMetadataProvider) Test(org.junit.Test)

Aggregations

MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)203 ArrayList (java.util.ArrayList)98 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)51 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)37 TdColumn (org.talend.cwm.relational.TdColumn)28 List (java.util.List)24 HashMap (java.util.HashMap)20 Test (org.junit.Test)15 TaggedValue (orgomg.cwm.objectmodel.core.TaggedValue)14 EList (org.eclipse.emf.common.util.EList)12 Indicator (org.talend.dataquality.indicators.Indicator)12 IRepositoryNode (org.talend.repository.model.IRepositoryNode)12 File (java.io.File)11 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 NoSQLExtractSchemaException (org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)10 Map (java.util.Map)9 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 Iterator (java.util.Iterator)8 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8