private void initializeContainer() {
    outputdataContainer = new IODataComponentContainer();
    for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
      if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)) {
        IODataComponent input = null;
        if (newInputMetadata == null) {
          input = new IODataComponent(connec);
        } else {
          if (connec.getMetaName().equals(newInputMetadata.getTableName())) {
            input = new IODataComponent(connec, newInputMetadata);
          }
        }
        if (input != null) {
          outputdataContainer.getInputs().add(input);
        }
      }
    }
    for (Connection connec : (List<Connection>) node.getOutgoingConnections()) {
      if (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN)
          || isinputContainerOutput(connec)
          || ((connec.getLineStyle().equals(EConnectionType.FLOW_MERGE)
              && (connec.getInputId() == 1)))) {
        if ((!connec.getSource().getConnectorFromType(connec.getLineStyle()).isMultiSchema())
            || (connec.getMetaName().equals(newOutputMetadata.getTableName()))) {
          IODataComponent output = new IODataComponent(connec, newOutputMetadata);
          outputdataContainer.getOuputs().add(output);
        }
      }
    }

    if (inputNode != null) {
      inputdataContainer = new IODataComponentContainer();
      for (Connection connec : (List<Connection>) inputNode.getOutgoingConnections()) {
        if (connec.getTarget().equals(node)) {
          if ((!connec.getSource().getConnectorFromType(connec.getLineStyle()).isMultiSchema())
              || (connec.getMetaName().equals(newInputMetadata.getTableName()))) {
            IODataComponent output = new IODataComponent(connec, newInputMetadata);
            inputdataContainer.getOuputs().add(output);
          }
        }
      }
    }
  }
 @Override
 public void handleTableRelevantParameters(
     Connection connection, IElement ele, IMetadataTable metadataTable) {
   if (ele == null || metadataTable == null) {
     return;
   }
   String tableName = metadataTable.getTableName();
   IElementParameter tableNameParameter =
       ele.getElementParameter(EHCatalogRepositoryToComponent.TABLE_NAME.getParameterName());
   if (tableNameParameter != null) {
     tableNameParameter.setValue(getRepositoryValueOfStringType(connection, tableName));
   }
   String partition = metadataTable.getAdditionalProperties().get(HCatalogConstants.PARTITIONS);
   if (StringUtils.isNotEmpty(partition)) {
     IElementParameter partitionParameter =
         ele.getElementParameter(EHCatalogRepositoryToComponent.PARTITION_NAME.getParameterName());
     if (partitionParameter != null) {
       String partitionName = ExtractMetaDataFromHCatalog.extractPartitionNameByJsonStr(partition);
       if (StringUtils.isNotEmpty(partitionName)) {
         partitionParameter.setValue(getRepositoryValueOfStringType(connection, partitionName));
       }
     }
   }
 }
Ejemplo n.º 3
0
  public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables, PigMapData mapData) {
    for (IMetadataTable meatadataTable : outputMetadataTables) {
      String name = meatadataTable.getTableName();
      OutputTable outputTable = null;
      for (OutputTable out : mapData.getOutputTables()) {
        if (out.getName() != null && out.getName().equals(name)) {
          outputTable = out;
          break;
        }
      }
      if (outputTable == null) {
        outputTable = PigmapFactory.eINSTANCE.createOutputTable();
        outputTable.setName(name);
        mapData.getOutputTables().add(outputTable);
      }

      List<IMetadataColumn> listColumns = meatadataTable.getListColumns();
      if (listColumns != null) {
        EList<TableNode> nodes = outputTable.getNodes();
        for (int i = 0; i < listColumns.size(); i++) {
          IMetadataColumn column = listColumns.get(i);
          TableNode found = null;
          int j = 0;
          for (; j < nodes.size(); j++) {
            TableNode node = nodes.get(j);
            if (node.getName() != null && node.getName().equals(column.getLabel())) {
              found = node;
              break;
            }
          }
          if (found != null) {
            // set in case talend type changed in metadata
            found.setType(column.getTalendType());
            if (i != j) {
              // do switch to keep the same sequence
              TableNode temp = nodes.get(j);
              nodes.remove(j);
              nodes.add(i, temp);
            }
          } else {
            found = PigmapFactory.eINSTANCE.createTableNode();
            found.setName(column.getLabel());
            found.setType(column.getTalendType());
            found.setNullable(column.isNullable());

            nodes.add(i, found);
          }
        }

        if (nodes.size() > listColumns.size()) {
          List unUsed = new ArrayList();
          for (int i = listColumns.size(); i < nodes.size(); i++) {
            TableNode node = nodes.get(i);
            PigMapUtil.detachConnectionsSouce(node, mapData);
            unUsed.add(node);
          }
          nodes.removeAll(unUsed);
        }
      }
      mapData.getOutputTables().add(outputTable);

      // re-build the connections in case any unnecessary connections are created because of
      // previous bugs and
      // can't be deleted
      rebuildOutputNodesConnections(outputTable.getNodes(), mapData);
    }
  }