Esempio n. 1
0
 public static List<VarNode> convertDefineFunctionsToVarNodes(
     MapperManager mapperManger, List<INode> iNodes) {
   List<VarNode> varNodes = new ArrayList<VarNode>();
   if (mapperManger != null) {
     PigMapComponent mapperComponent = mapperManger.getMapperComponent();
     iNodesDefineFunctions.clear();
     defineFunctionsAlias.clear();
     checkPigLoadIfDefineFunctions(mapperComponent, iNodes);
     iNodesDefineFunctions.addAll(iNodes);
     for (INode iNode : iNodes) {
       IElementParameter elementParameter =
           iNode.getElementParameter(PigMapConstants.DEFINE_FUNCTION);
       if (elementParameter != null && elementParameter.getValue() instanceof List) {
         List<Map<String, String>> defineFunctions =
             (List<Map<String, String>>) elementParameter.getValue();
         if (defineFunctions.size() > 0) {
           for (Map<String, String> item : defineFunctions) {
             VarNode newVarNode = PigmapFactory.eINSTANCE.createVarNode();
             newVarNode.setType(iNode.getUniqueName());
             newVarNode.setName(item.get(PigMapConstants.FUNCTION_ALIAS));
             newVarNode.setExpression(item.get(PigMapConstants.UDF_FUNCTION));
             varNodes.add(newVarNode);
             String key = item.get(PigMapConstants.FUNCTION_ALIAS);
             if (!defineFunctionsAlias.containsKey(key)) {
               defineFunctionsAlias.put(key, item.get(PigMapConstants.UDF_FUNCTION));
             }
           }
         }
       }
     }
   }
   return varNodes;
 }
Esempio n. 2
0
 public static void convertVarNodesToDefineFunctions(VarTable varTable) {
   // if you modified the configure of var define functions , we need update .
   defineFunctionsAlias.clear();
   for (VarNode varNode : varTable.getNodes()) {
     Map<String, String> item = new HashMap<String, String>();
     item.put(
         PigMapConstants.FUNCTION_ALIAS, TalendQuoteUtils.addQuotesIfNotExist(varNode.getName()));
     item.put(
         PigMapConstants.UDF_FUNCTION,
         TalendQuoteUtils.addQuotesIfNotExist(varNode.getExpression()));
     String key = varNode.getName();
     if (!defineFunctionsAlias.containsKey(key)) {
       defineFunctionsAlias.put(key, varNode.getExpression());
     }
   }
 }
Esempio n. 3
0
 public static void convertVarNodesToDefineFunctions(VarTable varTable, List<INode> iNodes) {
   // Send back the change to the tPigLoad node if you modified the configure of define dunctions
   for (INode iNode : iNodes) {
     IElementParameter elementParameter =
         iNode.getElementParameter(PigMapConstants.DEFINE_FUNCTION);
     if (elementParameter != null && elementParameter.getValue() instanceof List) {
       List<Map<String, String>> defineFunctions =
           (List<Map<String, String>>) elementParameter.getValue();
       defineFunctions.clear();
       defineFunctionsAlias.clear();
       for (VarNode varNode : varTable.getNodes()) {
         if (iNode.getUniqueName().equals(varNode.getType())) {
           Map<String, String> item = new HashMap<String, String>();
           item.put(
               PigMapConstants.FUNCTION_ALIAS,
               TalendQuoteUtils.addQuotesIfNotExist(varNode.getName()));
           if (varNode.getExpression() != null) {
             String newString = varNode.getExpression().trim();
             if (newString.length() > 0) {
               newString = TalendQuoteUtils.addQuotesIfNotExist(newString);
             }
             item.put(PigMapConstants.UDF_FUNCTION, newString);
           } else {
             item.put(PigMapConstants.UDF_FUNCTION, ""); // $NON-NLS-1$
           }
           defineFunctions.add(item);
           String key = varNode.getName();
           if (!defineFunctionsAlias.containsKey(key)) {
             defineFunctionsAlias.put(key, varNode.getExpression());
           }
         }
       }
     }
   }
 }