-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/LocalTimeFunction.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.time.LocalTime; | ||
import java.time.ZoneId; | ||
|
||
/** | ||
* LocalTimeFunction | ||
* description: | ||
* localTime([string1]) returns the current time in the specified time zone. | ||
* (by default: the current time in the system time zone) | ||
*/ | ||
public class LocalTimeFunction implements ValueParser { | ||
|
||
private ValueParser stringParser; | ||
|
||
public LocalTimeFunction(Function expr) { | ||
if (expr.getParameters() != null) { | ||
stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
if (stringParser != null) { | ||
String zoneString = OperatorTools.parseString(stringParser.parse(sourceData, rowIndex, context)); | ||
return LocalTime.now(ZoneId.of(zoneString)).withNano(0); | ||
} else { | ||
return LocalTime.now(ZoneId.systemDefault()).withNano(0); | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...orm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/LowerFunction.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,46 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* LowerFunction | ||
* description: LOWER(s): Convert all letters of the string s to lowercase letters | ||
*/ | ||
public class LowerFunction implements ValueParser { | ||
|
||
private ValueParser stringParser; | ||
|
||
public LowerFunction(Function expr) { | ||
stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object stringObj = stringParser.parse(sourceData, rowIndex, context); | ||
if (stringObj == null) | ||
return null; | ||
return stringObj.toString().toLowerCase(); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...form-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/RandFunction.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,61 @@ | ||
/* | ||
* 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.Expression; | ||
import net.sf.jsqlparser.expression.Function; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
/** | ||
* RandFunction | ||
* description: Rand()--Returns a pseudo-random double precision value in the range [0.0, 1.0) | ||
* Rand(Integer)--Returns a pseudo-random double precision value in the range [0.0, 1.0) with an initial seed of Integer. | ||
*/ | ||
public class RandFunction implements ValueParser { | ||
|
||
private ValueParser seedParser; | ||
|
||
private Random random; | ||
|
||
public RandFunction(Function expr) { | ||
random = new Random(); | ||
if (expr.getParameters() != null) { | ||
List<Expression> expressions = expr.getParameters().getExpressions(); | ||
if (expressions != null && expressions.size() == 1) { | ||
seedParser = OperatorTools.buildParser(expressions.get(0)); | ||
} | ||
} | ||
} | ||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
if (seedParser != null) { | ||
Object seedObj = seedParser.parse(sourceData, rowIndex, context); | ||
BigDecimal seedValue = OperatorTools.parseBigDecimal(seedObj); | ||
random.setSeed(seedValue.intValue()); | ||
} | ||
return random.nextDouble(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...orm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/UpperFunction.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,46 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* UpperFunction | ||
* description: UPPER(s): Convert a string to uppercase | ||
*/ | ||
public class UpperFunction implements ValueParser { | ||
|
||
private ValueParser stringParser; | ||
|
||
public UpperFunction(Function expr) { | ||
stringParser = OperatorTools.buildParser(expr.getParameters().getExpressions().get(0)); | ||
} | ||
|
||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex, Context context) { | ||
Object stringObj = stringParser.parse(sourceData, rowIndex, context); | ||
if (stringObj == null) | ||
return null; | ||
return stringObj.toString().toUpperCase(); | ||
} | ||
} |
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
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
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
Oops, something went wrong.