You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "Zkplo (via GitHub)" <gi...@apache.org> on 2024/08/25 07:10:45 UTC
[PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Zkplo opened a new pull request, #10880:
URL: https://github.com/apache/inlong/pull/10880
<!-- Prepare a Pull Request
Change the title of pull request refer to the following example:
[INLONG-XYZ][Component] Title of the pull request
-->
<!-- Specify the issue this pull request going to fix.
The following *XYZ* should be replaced by the actual [GitHub Issue](https://github.com/apache/inlong/issues) number)-->
Fixes #10879
### Motivation
Add one arithmetic function classe: TimestampAddFunction. Also, add the corresponding unit test codes.
<!--Explain here the context, and why you're making that change. What is the problem you're trying to solve.-->
### Modifications
<!--Describe the modifications you've done.-->
### Verifying this change
*(Please pick either of the following options)*
- [ ] This change is a trivial rework/code cleanup without any test coverage.
- [x] This change is already covered by existing tests, such as:
*(please describe tests)*
- [ ] This change added tests and can be verified as follows:
*(example:)*
- *Added integration tests for end-to-end deployment with large payloads (10MB)*
- *Extended integration test for recovery after broker failure*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang merged PR #10880:
URL: https://github.com/apache/inlong/pull/10880
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Posted by "Zkplo (via GitHub)" <gi...@apache.org>.
Zkplo commented on code in PR #10880:
URL: https://github.com/apache/inlong/pull/10880#discussion_r1730885155
##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TimestampAddFunction.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * TimestampAddFunction
+ * Description: Add integer expression intervals to the date or date time expression expr.
+ * The unit of the time interval is specified by the unit parameter, which should be one of the following values:
+ * FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
+ */
+public class TimestampAddFunction implements ValueParser {
+
+ private ValueParser intervalParser;
+ private ValueParser amountParser;
+ private ValueParser datetimeParser;
+ private static final String DEFAULT_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
+ private static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
+
+ public TimestampAddFunction(Function expr) {
+ List<Expression> expressions = expr.getParameters().getExpressions();
+ intervalParser = OperatorTools.buildParser(expressions.get(0));
+ amountParser = OperatorTools.buildParser(expressions.get(1));
+ datetimeParser = OperatorTools.buildParser(expressions.get(2));
+ }
+
+ @Override
+ public Object parse(SourceData sourceData, int rowIndex, Context context) {
+ String interval = intervalParser.parse(sourceData, rowIndex, context).toString();
+ Long amount = Long.parseLong(amountParser.parse(sourceData, rowIndex, context).toString());
+ String dateString = datetimeParser.parse(sourceData, rowIndex, context).toString();
+ return evalDate(dateString, interval, amount);
+ }
+
+ private String evalDate(String dateString, String interval, Long amount) {
+ DateTimeFormatter formatter = null;
+ LocalDateTime dateTime = null;
+ boolean hasTime = true;
+ if (dateString.indexOf(' ') != -1) {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE_TIME);
+ dateTime = LocalDateTime.parse(dateString, formatter);
+ } else {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE);
+ dateTime = LocalDate.parse(dateString, formatter).atStartOfDay();
+ hasTime = false;
+ }
+
+ switch (interval.toUpperCase()) {
+ case "FRAC_SECOND":
Review Comment:
"FRAC-SECOND" stands for milliseconds. No matter how high the accuracy is, other databases no longer support it. There is an error here that has been corrected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Posted by "Zkplo (via GitHub)" <gi...@apache.org>.
Zkplo commented on code in PR #10880:
URL: https://github.com/apache/inlong/pull/10880#discussion_r1732233246
##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TimestampAddFunction.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * TimestampAddFunction
+ * Description: Add integer expression intervals to the date or date time expression expr.
+ * The unit of the time interval is specified by the unit parameter, which should be one of the following values:
+ * FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
+ */
+public class TimestampAddFunction implements ValueParser {
+
+ private ValueParser intervalParser;
+ private ValueParser amountParser;
+ private ValueParser datetimeParser;
+ private static final String DEFAULT_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
+ private static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
+
+ public TimestampAddFunction(Function expr) {
+ List<Expression> expressions = expr.getParameters().getExpressions();
+ intervalParser = OperatorTools.buildParser(expressions.get(0));
+ amountParser = OperatorTools.buildParser(expressions.get(1));
+ datetimeParser = OperatorTools.buildParser(expressions.get(2));
+ }
+
+ @Override
+ public Object parse(SourceData sourceData, int rowIndex, Context context) {
+ String interval = intervalParser.parse(sourceData, rowIndex, context).toString();
+ Long amount = Long.parseLong(amountParser.parse(sourceData, rowIndex, context).toString());
+ String dateString = datetimeParser.parse(sourceData, rowIndex, context).toString();
+ return evalDate(dateString, interval, amount);
+ }
+
+ private String evalDate(String dateString, String interval, Long amount) {
+ DateTimeFormatter formatter = null;
+ LocalDateTime dateTime = null;
+ boolean hasTime = true;
+ if (dateString.indexOf(' ') != -1) {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE_TIME);
Review Comment:
Thank you, it has been modified. Please check.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #10880:
URL: https://github.com/apache/inlong/pull/10880#discussion_r1732216255
##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TimestampAddFunction.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * TimestampAddFunction
+ * Description: Add integer expression intervals to the date or date time expression expr.
+ * The unit of the time interval is specified by the unit parameter, which should be one of the following values:
+ * FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
+ */
+public class TimestampAddFunction implements ValueParser {
+
+ private ValueParser intervalParser;
+ private ValueParser amountParser;
+ private ValueParser datetimeParser;
+ private static final String DEFAULT_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
+ private static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
+
+ public TimestampAddFunction(Function expr) {
+ List<Expression> expressions = expr.getParameters().getExpressions();
+ intervalParser = OperatorTools.buildParser(expressions.get(0));
+ amountParser = OperatorTools.buildParser(expressions.get(1));
+ datetimeParser = OperatorTools.buildParser(expressions.get(2));
+ }
+
+ @Override
+ public Object parse(SourceData sourceData, int rowIndex, Context context) {
+ String interval = intervalParser.parse(sourceData, rowIndex, context).toString();
+ Long amount = Long.parseLong(amountParser.parse(sourceData, rowIndex, context).toString());
+ String dateString = datetimeParser.parse(sourceData, rowIndex, context).toString();
+ return evalDate(dateString, interval, amount);
+ }
+
+ private String evalDate(String dateString, String interval, Long amount) {
+ DateTimeFormatter formatter = null;
+ LocalDateTime dateTime = null;
+ boolean hasTime = true;
+ if (dateString.indexOf(' ') != -1) {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE_TIME);
Review Comment:
As @luchunliang said, we should not create a new `DateTimeFormatter` every time we call this function, this is time and memory costly.
It's better to initialize only one `DateTimeFormatter` for every pattern.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Posted by "luchunliang (via GitHub)" <gi...@apache.org>.
luchunliang commented on code in PR #10880:
URL: https://github.com/apache/inlong/pull/10880#discussion_r1730717129
##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TimestampAddFunction.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * TimestampAddFunction
+ * Description: Add integer expression intervals to the date or date time expression expr.
+ * The unit of the time interval is specified by the unit parameter, which should be one of the following values:
+ * FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
+ */
+public class TimestampAddFunction implements ValueParser {
+
+ private ValueParser intervalParser;
+ private ValueParser amountParser;
+ private ValueParser datetimeParser;
+ private static final String DEFAULT_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
+ private static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
+
+ public TimestampAddFunction(Function expr) {
+ List<Expression> expressions = expr.getParameters().getExpressions();
+ intervalParser = OperatorTools.buildParser(expressions.get(0));
+ amountParser = OperatorTools.buildParser(expressions.get(1));
+ datetimeParser = OperatorTools.buildParser(expressions.get(2));
+ }
+
+ @Override
+ public Object parse(SourceData sourceData, int rowIndex, Context context) {
+ String interval = intervalParser.parse(sourceData, rowIndex, context).toString();
+ Long amount = Long.parseLong(amountParser.parse(sourceData, rowIndex, context).toString());
+ String dateString = datetimeParser.parse(sourceData, rowIndex, context).toString();
+ return evalDate(dateString, interval, amount);
+ }
+
+ private String evalDate(String dateString, String interval, Long amount) {
+ DateTimeFormatter formatter = null;
+ LocalDateTime dateTime = null;
+ boolean hasTime = true;
+ if (dateString.indexOf(' ') != -1) {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE_TIME);
Review Comment:
DateTimeFormatter.ofPattern is a complex operation that affects performance, and needs to be constructed in advance as a member variable. Additionally, it needs to support thread safety, so it is recommended to use ThreadLocal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Posted by "Zkplo (via GitHub)" <gi...@apache.org>.
Zkplo commented on code in PR #10880:
URL: https://github.com/apache/inlong/pull/10880#discussion_r1730795921
##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TimestampAddFunction.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * TimestampAddFunction
+ * Description: Add integer expression intervals to the date or date time expression expr.
+ * The unit of the time interval is specified by the unit parameter, which should be one of the following values:
+ * FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
+ */
+public class TimestampAddFunction implements ValueParser {
+
+ private ValueParser intervalParser;
+ private ValueParser amountParser;
+ private ValueParser datetimeParser;
+ private static final String DEFAULT_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
+ private static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
+
+ public TimestampAddFunction(Function expr) {
+ List<Expression> expressions = expr.getParameters().getExpressions();
+ intervalParser = OperatorTools.buildParser(expressions.get(0));
+ amountParser = OperatorTools.buildParser(expressions.get(1));
+ datetimeParser = OperatorTools.buildParser(expressions.get(2));
+ }
+
+ @Override
+ public Object parse(SourceData sourceData, int rowIndex, Context context) {
+ String interval = intervalParser.parse(sourceData, rowIndex, context).toString();
+ Long amount = Long.parseLong(amountParser.parse(sourceData, rowIndex, context).toString());
+ String dateString = datetimeParser.parse(sourceData, rowIndex, context).toString();
+ return evalDate(dateString, interval, amount);
+ }
+
+ private String evalDate(String dateString, String interval, Long amount) {
+ DateTimeFormatter formatter = null;
+ LocalDateTime dateTime = null;
+ boolean hasTime = true;
+ if (dateString.indexOf(' ') != -1) {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE_TIME);
Review Comment:
Thank you for your suggestion. DateTimeFormatter is thread safe, so is it feasible to directly use it as a member variable?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [INLONG-10879][SDK] Transform support TIMESTAMPADD() function [inlong]
Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #10880:
URL: https://github.com/apache/inlong/pull/10880#discussion_r1730814636
##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/TimestampAddFunction.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+
+/**
+ * TimestampAddFunction
+ * Description: Add integer expression intervals to the date or date time expression expr.
+ * The unit of the time interval is specified by the unit parameter, which should be one of the following values:
+ * FRAC_SECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, or YEAR.
+ */
+public class TimestampAddFunction implements ValueParser {
+
+ private ValueParser intervalParser;
+ private ValueParser amountParser;
+ private ValueParser datetimeParser;
+ private static final String DEFAULT_FORMAT_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
+ private static final String DEFAULT_FORMAT_DATE = "yyyy-MM-dd";
+
+ public TimestampAddFunction(Function expr) {
+ List<Expression> expressions = expr.getParameters().getExpressions();
+ intervalParser = OperatorTools.buildParser(expressions.get(0));
+ amountParser = OperatorTools.buildParser(expressions.get(1));
+ datetimeParser = OperatorTools.buildParser(expressions.get(2));
+ }
+
+ @Override
+ public Object parse(SourceData sourceData, int rowIndex, Context context) {
+ String interval = intervalParser.parse(sourceData, rowIndex, context).toString();
+ Long amount = Long.parseLong(amountParser.parse(sourceData, rowIndex, context).toString());
+ String dateString = datetimeParser.parse(sourceData, rowIndex, context).toString();
+ return evalDate(dateString, interval, amount);
+ }
+
+ private String evalDate(String dateString, String interval, Long amount) {
+ DateTimeFormatter formatter = null;
+ LocalDateTime dateTime = null;
+ boolean hasTime = true;
+ if (dateString.indexOf(' ') != -1) {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE_TIME);
+ dateTime = LocalDateTime.parse(dateString, formatter);
+ } else {
+ formatter = DateTimeFormatter.ofPattern(DEFAULT_FORMAT_DATE);
+ dateTime = LocalDate.parse(dateString, formatter).atStartOfDay();
+ hasTime = false;
+ }
+
+ switch (interval.toUpperCase()) {
+ case "FRAC_SECOND":
Review Comment:
why not support microsecond and millisecond?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org