Review Board 1.7.22


Implemented trigonometric functions as part of DRILL 219

Review Request #14318 - Created Sept. 24, 2013 and updated

Yash Sharma
Reviewers
drill-git
drill-git
Implemented trigonometric functions as part of DRILL 219.
Updated the patch.
Added null checks for null inputs.
Yes.
$ mvn test -Dtest=RunSimplePlan#mathTrigonometricPlan


{
  "tanh" : 1.0,
  "cosh" : 1.4524424832623713E13,
  "atan" : 1.5385494443596428,
  "asin" : "NaN",
  "cos" : 0.9147423578045313,
  "sin" : -0.404037645323065,
  "sinh" : 1.4524424832623713E13,
  "acos" : "NaN",
  "tan" : -0.441695568020698
} 
 {
  "tanh" : 1.0,
  "cosh" : 1.0732178989295803E14,
  "atan" : 1.5405025668761214,
  "asin" : "NaN",
  "cos" : -0.013276747223059479,
  "sin" : 0.9999118601072672,
  "sinh" : 1.0732178989295803E14,
  "acos" : "NaN",
  "tan" : -75.31301480008509
} 
 {
  "tanh" : 1.0,
  "cosh" : 1.0732178989295803E14,
  "atan" : 1.5405025668761214,
  "asin" : "NaN",
  "cos" : -0.013276747223059479,
  "sin" : 0.9999118601072672,
  "sinh" : 1.0732178989295803E14,
  "acos" : "NaN",
  "tan" : -75.31301480008509
} 
 {
  "tanh" : 1.0,
  "cosh" : 2.9173087126372744E14,
  "atan" : 1.5413930385908916,
  "asin" : "NaN",
  "cos" : -0.8485702747846052,
  "sin" : 0.5290826861200238,
  "sinh" : 2.9173087126372744E14,
  "acos" : "NaN",
  "tan" : -0.6234989627162255
} 
 {
  "tanh" : 1.0,
  "cosh" : 2.9173087126372744E14,
  "atan" : 1.5413930385908916,
  "asin" : "NaN",
  "cos" : -0.8485702747846052,
  "sin" : 0.5290826861200238,
  "sinh" : 2.9173087126372744E14,
  "acos" : "NaN",
  "tan" : -0.6234989627162255
} 
 {
  "tanh" : "NaN",
  "cosh" : "NaN",
  "atan" : "NaN",
  "asin" : "NaN",
  "cos" : "NaN",
  "sin" : "NaN",
  "sinh" : "NaN",
  "acos" : "NaN",
  "tan" : "NaN"
} 
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.389 sec - in org.apache.drill.exec.ref.RunSimplePlan

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.114s
[INFO] Finished at: Tue Sep 24 13:49:39 IST 2013
[INFO] Final Memory: 22M/52M
[INFO] ------------------------------------------------------------------------
common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java
Revision ee3a099 New Change
[20] 14 lines
[+20]
15
 * See the License for the specific language governing permissions and
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
16
 * limitations under the License.
17
 */
17
 */
18
package org.apache.drill.common.expression.fn;
18
package org.apache.drill.common.expression.fn;
19

    
   
19

   

    
   
20
import org.apache.drill.common.expression.Arg;
20
import org.apache.drill.common.expression.ArgumentValidators;
21
import org.apache.drill.common.expression.ArgumentValidators;

    
   
22
import org.apache.drill.common.expression.BasicArgumentValidator;
21
import org.apache.drill.common.expression.FunctionDefinition;
23
import org.apache.drill.common.expression.FunctionDefinition;
22
import org.apache.drill.common.expression.CallProvider;
24
import org.apache.drill.common.expression.CallProvider;
23
import org.apache.drill.common.expression.OutputTypeDeterminer;
25
import org.apache.drill.common.expression.OutputTypeDeterminer;

    
   
26
import org.apache.drill.common.types.TypeProtos;

    
   
27
import org.apache.drill.common.types.Types;
24

    
   
28

   
25

    
   
29

   
26

    
   
30

   
27
public class MathFunctions implements CallProvider{
31
public class MathFunctions implements CallProvider{
28
	
32
	
[+20] [20] 4 lines
[+20] [+] public FunctionDefinition[] getFunctionDefintions() {
33
        FunctionDefinition.operator("add", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "+"),
37
        FunctionDefinition.operator("add", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "+"),
34
        FunctionDefinition.operator("subtract", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "-"),
38
        FunctionDefinition.operator("subtract", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "-"),
35
        FunctionDefinition.operator("divide", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "/"),
39
        FunctionDefinition.operator("divide", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "/"),
36
        FunctionDefinition.operator("multiply", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "*"),
40
        FunctionDefinition.operator("multiply", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "*"),
37
        FunctionDefinition.operator("modulo", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "%"),
41
        FunctionDefinition.operator("modulo", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "%"),

    
   
42
        FunctionDefinition.simple("floatcos", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "cos"),

    
   
43
        FunctionDefinition.simple("floatsin", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "sin"),

    
   
44
        FunctionDefinition.simple("floattan", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "tan"),

    
   
45
        FunctionDefinition.simple("floatcosh", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "cosh"),

    
   
46
        FunctionDefinition.simple("floatsinh", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "sinh"),

    
   
47
        FunctionDefinition.simple("floattanh", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "tanh"),

    
   
48
        FunctionDefinition.simple("floatacos", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "acos"),

    
   
49
        FunctionDefinition.simple("floatasin", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "asin"),

    
   
50
        FunctionDefinition.simple("floatatan", new BasicArgumentValidator(new Arg(Types.required(TypeProtos.MinorType.FLOAT8))), new OutputTypeDeterminer.SameAsAnySoft(), "atan"),
38
        XOR
51
        XOR
39
    };
52
    };
40

    
   
53

   
41
  }
54
  }
42
  
55
  
43
	public static final FunctionDefinition XOR = FunctionDefinition.operator("xor", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "^");
56
	public static final FunctionDefinition XOR = FunctionDefinition.operator("xor", new ArgumentValidators.NumericTypeAllowed(1, Integer.MAX_VALUE, true), new OutputTypeDeterminer.SameAsAnySoft(), "^");
44
}
57
}
exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java
Revision 288760b New Change
 
exec/ref/src/main/java/org/apache/drill/exec/ref/eval/fn/MathEvaluators.java
Revision 347a4f3 New Change
 
exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java
Revision f4992e0 New Change
 
exec/ref/src/test/resources/trigo_math.json
New File
 
  1. common/src/main/java/org/apache/drill/common/expression/fn/MathFunctions.java: Loading...
  2. exec/java-exec/src/main/java/org/apache/drill/exec/expr/fn/impl/MathFunctions.java: Loading...
  3. exec/ref/src/main/java/org/apache/drill/exec/ref/eval/fn/MathEvaluators.java: Loading...
  4. exec/ref/src/test/java/org/apache/drill/exec/ref/RunSimplePlan.java: Loading...
  5. exec/ref/src/test/resources/trigo_math.json: Loading...