예제 #1
0
  public void rebuildModelInputs(List<? extends IConnection> inputConn, PigMapData mapData) {
    // remove no used input table
    if (mapData.getInputTables().size() != inputConn.size()) {
      List tableToRemove = new ArrayList();
      for (InputTable inputTable : mapData.getInputTables()) {
        boolean found = false;
        for (IConnection connection : inputConn) {
          if (inputTable.getName().equals(connection.getName())) {
            found = true;
          }
        }
        if (!found) {
          for (TableNode tableNode : inputTable.getNodes()) {
            PigMapUtil.detachNodeConnections(tableNode, mapData);
          }
          tableToRemove.add(inputTable);
          PigMapUtil.detachFilterSource(inputTable, mapData);
        }
      }
      mapData.getInputTables().removeAll(tableToRemove);
    }

    for (IConnection inData : inputConn) {
      String name = inData.getName();
      InputTable inputTable = null;
      for (InputTable in : mapData.getInputTables()) {
        if (in.getName() != null && in.getName().equals(name)) {
          inputTable = in;
          break;
        }
      }
      if (inputTable == null) {
        inputTable = PigmapFactory.eINSTANCE.createInputTable();
        inputTable.setName(name);
        inputTable.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
        mapData
            .getInputTables()
            .add(inputTable.isLookup() ? mapData.getInputTables().size() : 0, inputTable);
      } else {
        inputTable.setLookup(EConnectionType.FLOW_MAIN != inData.getLineStyle());
      }
      // by default
      if (inputTable.isLookup() && inputTable.getJoinModel() == null) {
        inputTable.setJoinModel(TableSettingsConstant.LEFT_OUTER_JOIN);
      }
      if (inputTable.isLookup() && inputTable.getJoinOptimization() == null) {
        inputTable.setJoinOptimization(PIG_MAP_JOIN_OPTIMIZATION.NONE.toString());
      }
      rebuildInputTable(inputTable, inData.getMetadataTable(), mapData);
    }
  }
예제 #2
0
  public void rebuildInputTable(
      InputTable inputTable, IMetadataTable metadataTable, PigMapData mapData) {
    if (metadataTable != null && metadataTable.getListColumns() != null) {
      List<IMetadataColumn> listColumns = metadataTable.getListColumns();
      EList<TableNode> nodes = inputTable.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++) {
          PigMapUtil.detachNodeConnections(nodes.get(i), mapData);
          unUsed.add(nodes.get(i));
        }
        nodes.removeAll(unUsed);
      }
    }

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