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-10130][SDK] Transform SQL support string concat function (apa…
- Loading branch information
1 parent
fc98df6
commit cacbd4d
Showing
4 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
...rm-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/ConcatFunction.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,70 @@ | ||
/* | ||
* 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.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.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* ConcatFunction | ||
* | ||
*/ | ||
public class ConcatFunction implements ValueParser { | ||
|
||
private List<ValueParser> nodeList; | ||
|
||
/** | ||
* Constructor | ||
* @param expr | ||
*/ | ||
public ConcatFunction(Function expr) { | ||
if (expr.getParameters() == null) { | ||
this.nodeList = new ArrayList<>(); | ||
} else { | ||
List<Expression> params = expr.getParameters().getExpressions(); | ||
nodeList = new ArrayList<>(params.size()); | ||
for (Expression param : params) { | ||
ValueParser node = OperatorTools.buildParser(param); | ||
nodeList.add(node); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* parse | ||
* @param sourceData | ||
* @param rowIndex | ||
* @return | ||
*/ | ||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex) { | ||
StringBuilder builder = new StringBuilder(); | ||
for (ValueParser node : nodeList) { | ||
builder.append(node.parse(sourceData, rowIndex)); | ||
} | ||
return builder.toString(); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...sform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/NowFunction.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.parser.ValueParser; | ||
|
||
import net.sf.jsqlparser.expression.Function; | ||
|
||
/** | ||
* NowFunction | ||
* | ||
*/ | ||
public class NowFunction implements ValueParser { | ||
|
||
/** | ||
* Constructor | ||
* @param expr | ||
*/ | ||
public NowFunction(Function expr) { | ||
} | ||
|
||
/** | ||
* parse | ||
* @param sourceData | ||
* @param rowIndex | ||
* @return | ||
*/ | ||
@Override | ||
public Object parse(SourceData sourceData, int rowIndex) { | ||
return String.valueOf(System.currentTimeMillis()); | ||
} | ||
} |
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