forked from apache/inlong
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INLONG-11114][SDK] Transform support Trigonometric function in units…
… of degrees
- Loading branch information
Showing
16 changed files
with
831 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...orm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/AcosdFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.transform.process.function; | ||
|
||
import org.apache.inlong.sdk.transform.decode.SourceData; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.operator.OperatorTools; | ||
import org.apache.inlong.sdk.transform.process.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* AcosdFunction | ||
* description: acosd(numeric)--returns the arc cosine of numeric in units of degrees | ||
*/ | ||
@TransformFunction(names = {"acosd"}) | ||
public class AcosdFunction implements ValueParser { | ||
|
||
private ValueParser numberParser; | ||
|
||
public AcosdFunction(Function expr) { | ||
numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object numberObj = numberParser.parse(sourceData, rowIndex, context); | ||
BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); | ||
return Math.toDegrees(Math.acos(numberValue.doubleValue())); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...orm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/AsindFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.transform.process.function; | ||
|
||
import org.apache.inlong.sdk.transform.decode.SourceData; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.operator.OperatorTools; | ||
import org.apache.inlong.sdk.transform.process.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* AsindFunction | ||
* description: asind(numeric)--returns the arc sine of numeric in units of degrees | ||
*/ | ||
@TransformFunction(names = {"asind"}) | ||
public class AsindFunction implements ValueParser { | ||
|
||
private ValueParser numberParser; | ||
|
||
public AsindFunction(Function expr) { | ||
numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object numberObj = numberParser.parse(sourceData, rowIndex, context); | ||
BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); | ||
return Math.toDegrees(Math.asin(numberValue.doubleValue())); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...rm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/Atan2dFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.transform.process.function; | ||
|
||
import org.apache.inlong.sdk.transform.decode.SourceData; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.operator.OperatorTools; | ||
import org.apache.inlong.sdk.transform.process.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* Atan2dFunction | ||
* description: asind(numeric)--returns the arc sine of numeric in units of degrees | ||
*/ | ||
@TransformFunction(names = {"atan2d"}) | ||
public class Atan2dFunction implements ValueParser { | ||
|
||
private ValueParser xParser; | ||
private ValueParser yParser; | ||
|
||
public Atan2dFunction(Function expr) { | ||
xParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
yParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(1)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object xObj = xParser.parse(sourceData, rowIndex, context); | ||
Object yObj = yParser.parse(sourceData, rowIndex, context); | ||
|
||
if (xObj == null) { | ||
throw new NullPointerException("Parsed number object on the x-axis is null"); | ||
} | ||
|
||
BigDecimal xValue = OperatorTools.parseBigDecimal(xObj); | ||
BigDecimal yValue = OperatorTools.parseBigDecimal(yObj); | ||
|
||
return Math.toDegrees(Math.atan2(xValue.doubleValue(), yValue.doubleValue())); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...orm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/AtandFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.transform.process.function; | ||
|
||
import org.apache.inlong.sdk.transform.decode.SourceData; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.operator.OperatorTools; | ||
import org.apache.inlong.sdk.transform.process.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* AtandFunction | ||
* description: atand(numeric)--returns the arc tangent of numeric in units of degrees | ||
*/ | ||
@TransformFunction(names = {"atand"}) | ||
public class AtandFunction implements ValueParser { | ||
|
||
private ValueParser numberParser; | ||
|
||
public AtandFunction(Function expr) { | ||
numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object numberObj = numberParser.parse(sourceData, rowIndex, context); | ||
BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); | ||
return Math.toDegrees(Math.atan(numberValue.doubleValue())); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...form-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/CosdFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.transform.process.function; | ||
|
||
import org.apache.inlong.sdk.transform.decode.SourceData; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.operator.OperatorTools; | ||
import org.apache.inlong.sdk.transform.process.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* CosdFunction | ||
* description: cosd(numeric)--returns the cosine of numeric in units of degrees | ||
*/ | ||
@TransformFunction(names = {"cosd"}) | ||
public class CosdFunction implements ValueParser { | ||
|
||
private ValueParser numberParser; | ||
|
||
public CosdFunction(Function expr) { | ||
numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object numberObj = numberParser.parse(sourceData, rowIndex, context); | ||
BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); | ||
return Math.cos(Math.toRadians(numberValue.doubleValue())); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...form-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/CotdFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.transform.process.function; | ||
|
||
import org.apache.inlong.sdk.transform.decode.SourceData; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.operator.OperatorTools; | ||
import org.apache.inlong.sdk.transform.process.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* CotdFunction | ||
* description: cotd(numeric)--returns the cotangent of numeric in units of degrees | ||
*/ | ||
@TransformFunction(names = {"cotd"}) | ||
public class CotdFunction implements ValueParser { | ||
|
||
private ValueParser numberParser; | ||
|
||
public CotdFunction(Function expr) { | ||
numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object valueObj = numberParser.parse(sourceData, rowIndex, context); | ||
|
||
BigDecimal value = OperatorTools.parseBigDecimal(valueObj); | ||
|
||
// Calculate tan(x) and take the inverse to find cot(x) | ||
double tanValue = Math.tan(Math.toRadians(value.doubleValue())); | ||
if (tanValue == 0) { | ||
throw new ArithmeticException("Cotangent undefined for this input, tan(x) is zero."); | ||
} | ||
return 1.0 / tanValue; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...form-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/SindFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.inlong.sdk.transform.process.function; | ||
|
||
import org.apache.inlong.sdk.transform.decode.SourceData; | ||
import org.apache.inlong.sdk.transform.process.Context; | ||
import org.apache.inlong.sdk.transform.process.operator.OperatorTools; | ||
import org.apache.inlong.sdk.transform.process.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* SindFunction | ||
* description: sind(numeric)--returns the sine of numeric in units of degrees | ||
*/ | ||
@TransformFunction(names = {"sind"}) | ||
public class SindFunction implements ValueParser { | ||
|
||
private ValueParser numberParser; | ||
|
||
public SindFunction(Function expr) { | ||
numberParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object numberObj = numberParser.parse(sourceData, rowIndex, context); | ||
BigDecimal numberValue = OperatorTools.parseBigDecimal(numberObj); | ||
return Math.sin(Math.toRadians(numberValue.doubleValue())); | ||
} | ||
} |
Oops, something went wrong.