[ 
https://issues.apache.org/jira/browse/APEXMALHAR-2010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15203808#comment-15203808
 ] 

ASF GitHub Bot commented on APEXMALHAR-2010:
--------------------------------------------

Github user chinmaykolhatkar commented on a diff in the pull request:

    
https://github.com/apache/incubator-apex-malhar/pull/209#discussion_r56785718
  
    --- Diff: library/src/main/java/com/datatorrent/lib/util/PojoUtils.java ---
    @@ -696,11 +662,97 @@ private static Object createSetter(Class<?> 
pojoClass, String setterExpr, String
           code = getSingleFieldSetterExpression(pojoClass, setterExpr, 
exprClass);
         }
     
    +    return compileExpression(code, setterClass, new String[] 
{PojoUtils.OBJECT, PojoUtils.VAL});
    +  }
    +
    +  /**
    +   * This method takes in expression, compiles the expression to provide a 
executable form of expression.
    +   * This method uses {@link 
com.datatorrent.lib.expression.JavaExpressionParser} as expression parser.
    +   *
    +   * @param inputType  Type of input object
    +   * @param expr       expression to be compiled.
    +   * @param returnType Return type of the expression.
    +   * @return Object of type {@link Expression} which can be directly 
executed.
    +   */
    +  public static Expression createExpression(Class<?> inputType, String 
expr, Class<?> returnType)
    +  {
    +    return createExpression(inputType, expr, returnType, null);
    +  }
    +
    +  /**
    +   * This method takes in expression, compiles the expression to provide a 
executable form of expression.
    +   * This methods also takes in list of classes and method which can be 
imported statically in expression.
    +   * <p/>
    +   * This method uses {@link JavaExpressionParser} as expression parser.
    +   *
    +   * @param inputType      Type of input object
    +   * @param expr           expression to be compiled.
    +   * @param returnType     Return type of the expression.
    +   * @param defaultImports List of classes/method which will be statically 
imported to expression compilation.
    +   * @return Object of type {@link Expression} which can be directly 
executed.
    +   */
    +  public static Expression createExpression(Class<?> inputType, String 
expr, Class<?> returnType,
    +      String[] defaultImports)
    +  {
    +    JavaExpressionParser javaExpressionParser = new JavaExpressionParser();
    +    javaExpressionParser.setInputObjectPlaceholder("$", PojoUtils.OBJECT);
    +
    +    return createExpression(inputType, expr, returnType, defaultImports, 
javaExpressionParser);
    +  }
    +
    +  /**
    +   * This method takes in expression, compiles the expression to provide a 
executable form of expression.
    +   * This methods also takes in list of classes and method which can be 
imported statically in expression.
    +   * <p/>
    +   * Using this method one can override expression parser implementation.
    +   *
    +   * @param inputType      Type of input object
    +   * @param expr           expression to be compiled.
    +   * @param returnType     Return type of the expression.
    +   * @param defaultImports List of classes/method which will be statically 
imported to expression compilation.
    +   * @param parser         Expression parser that should be used to parse 
expression.
    +   * @return Object of type {@link Expression} which can be directly 
executed.
    +   * @see {@link JavaExpressionParser} as a example.
    +   */
    +  public static Expression createExpression(Class<?> inputType, String 
expr, Class<?> returnType,
    +      String[] defaultImports, Expression.ExpressionParser parser)
    +  {
    +    String code = parser.convertToCompilableExpression(expr, inputType, 
returnType);
    +
    +    return (Expression)compileExpression(code, Expression.class, new 
String[] {PojoUtils.OBJECT}, defaultImports);
    +  }
    +
    +  private static Object compileExpression(String code, Class<?> implClass, 
String[] params)
    +  {
    +    return compileExpression(code, implClass, params, null);
    +  }
    +
    +  private static Object compileExpression(String code, Class<?> implClass, 
String[] params, String[] defaultImports)
    +  {
    +    List<String> imports = new LinkedList<>();
    +    if (defaultImports != null && defaultImports.length != 0) {
    +      for (String defaultImport : defaultImports) {
    +        if (!defaultImport.startsWith("static")) {
    --- End diff --
    
    When adding a given import as static, that means the method will be 
directly available in expression to be used. This way, the expression writer 
can use similar syntax like excel functions.


> Add transform operator
> ----------------------
>
>                 Key: APEXMALHAR-2010
>                 URL: https://issues.apache.org/jira/browse/APEXMALHAR-2010
>             Project: Apache Apex Malhar
>          Issue Type: New Feature
>          Components: algorithms
>    Affects Versions: 3.4.0
>            Reporter: Chinmay Kolhatkar
>            Assignee: Chinmay Kolhatkar
>
> Add transform operator
> Details to be added soon once the mailing thread reaching conclusion:
> http://mail-archives.apache.org/mod_mbox/incubator-apex-dev/201603.mbox/%3CCABAipVZUdRGx5dS35bYPN46koLQU5gSLgbCeRH8aM_y9ANRU2w%40mail.gmail.com%3E



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to