You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "yfsn666 (via GitHub)" <gi...@apache.org> on 2024/08/08 08:38:45 UTC

[PR] [INLONG-10764][SDK] Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth) [inlong]

yfsn666 opened a new pull request, #10766:
URL: https://github.com/apache/inlong/pull/10766

   <!-- 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 #10764
   
   ### Motivation
   
   <!--Explain here the context, and why you're making that change. What is the problem you're trying to solve.-->
   Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth)
   
   ### Modifications
   
   <!--Describe the modifications you've done.-->
   Add one temporal function class `DateExtractFunction` and one class `DateParser` that implements the class `ValueParser`. Also, add the corresponding unit test codes
   
   ### 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 in `TestTransformTemporalFunctionsProcessor.java`
     *(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*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? yes
     - If yes, how is the feature documented? not documented
   


-- 
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-10764][SDK] Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth) [inlong]

Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang merged PR #10766:
URL: https://github.com/apache/inlong/pull/10766


-- 
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-10764][SDK] Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth) [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #10766:
URL: https://github.com/apache/inlong/pull/10766#discussion_r1710575837


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/DateExtractFunction.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.sql.Date;
+import java.time.LocalDate;
+import java.time.temporal.TemporalField;
+import java.time.temporal.WeekFields;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * DateExtractFunction
+ * description:
+ * - year(date)--returns the year from SQL date date
+ * - quarter(date)--returns the quarter of a year (an integer between 1 and 4) from SQL date date
+ * - month(date)--returns the month of a year (an integer between 1 and 12) from SQL date date
+ * - week(date)--returns the week of a year (an integer between 1 and 53) from SQL date date
+ * - dayofyear(date)--returns the day of a year (an integer between 1 and 366) from SQL date date
+ * - dayofmonth(date)--returns the day of a month (an integer between 1 and 31) from SQL date date
+ */
+public class DateExtractFunction implements ValueParser {
+
+    private int type;
+    private ValueParser dateParser;
+    private static final TemporalField weekOfYearField = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
+
+    /**
+     * Constructor
+     *
+     * @param type the type of date extract function(1->year, 2->quarter, 3->month, 4->week, 5->dayofyear, 6->dayofmonth)
+     * @param expr
+     */
+    public DateExtractFunction(int type, Function expr) {
+        this.type = type;
+        List<Expression> expressions = expr.getParameters().getExpressions();
+        dateParser = OperatorTools.buildParser(expressions.get(0));
+    }

Review Comment:
   Why not use meaningful words to represent the type like "YEAR", "MONTH"?
   



-- 
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-10764][SDK] Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth) [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #10766:
URL: https://github.com/apache/inlong/pull/10766#discussion_r1710575837


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/DateExtractFunction.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.sql.Date;
+import java.time.LocalDate;
+import java.time.temporal.TemporalField;
+import java.time.temporal.WeekFields;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * DateExtractFunction
+ * description:
+ * - year(date)--returns the year from SQL date date
+ * - quarter(date)--returns the quarter of a year (an integer between 1 and 4) from SQL date date
+ * - month(date)--returns the month of a year (an integer between 1 and 12) from SQL date date
+ * - week(date)--returns the week of a year (an integer between 1 and 53) from SQL date date
+ * - dayofyear(date)--returns the day of a year (an integer between 1 and 366) from SQL date date
+ * - dayofmonth(date)--returns the day of a month (an integer between 1 and 31) from SQL date date
+ */
+public class DateExtractFunction implements ValueParser {
+
+    private int type;
+    private ValueParser dateParser;
+    private static final TemporalField weekOfYearField = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
+
+    /**
+     * Constructor
+     *
+     * @param type the type of date extract function(1->year, 2->quarter, 3->month, 4->week, 5->dayofyear, 6->dayofmonth)
+     * @param expr
+     */
+    public DateExtractFunction(int type, Function expr) {
+        this.type = type;
+        List<Expression> expressions = expr.getParameters().getExpressions();
+        dateParser = OperatorTools.buildParser(expressions.get(0));
+    }

Review Comment:
   Why not use meaningful words to represent the type like "YEAR", "MONTH"



-- 
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-10764][SDK] Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth) [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #10766:
URL: https://github.com/apache/inlong/pull/10766#discussion_r1710575837


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/DateExtractFunction.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.sql.Date;
+import java.time.LocalDate;
+import java.time.temporal.TemporalField;
+import java.time.temporal.WeekFields;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * DateExtractFunction
+ * description:
+ * - year(date)--returns the year from SQL date date
+ * - quarter(date)--returns the quarter of a year (an integer between 1 and 4) from SQL date date
+ * - month(date)--returns the month of a year (an integer between 1 and 12) from SQL date date
+ * - week(date)--returns the week of a year (an integer between 1 and 53) from SQL date date
+ * - dayofyear(date)--returns the day of a year (an integer between 1 and 366) from SQL date date
+ * - dayofmonth(date)--returns the day of a month (an integer between 1 and 31) from SQL date date
+ */
+public class DateExtractFunction implements ValueParser {
+
+    private int type;
+    private ValueParser dateParser;
+    private static final TemporalField weekOfYearField = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
+
+    /**
+     * Constructor
+     *
+     * @param type the type of date extract function(1->year, 2->quarter, 3->month, 4->week, 5->dayofyear, 6->dayofmonth)
+     * @param expr
+     */
+    public DateExtractFunction(int type, Function expr) {
+        this.type = type;
+        List<Expression> expressions = expr.getParameters().getExpressions();
+        dateParser = OperatorTools.buildParser(expressions.get(0));
+    }

Review Comment:
   Why not use meaningful words to represent the type like "YEAR", "MONTH"?
   int type value of 1,2,3,4,5,6 is not understandable to users.
   



-- 
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-10764][SDK] Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth) [inlong]

Posted by "yfsn666 (via GitHub)" <gi...@apache.org>.
yfsn666 commented on code in PR #10766:
URL: https://github.com/apache/inlong/pull/10766#discussion_r1710597484


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/DateExtractFunction.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.sql.Date;
+import java.time.LocalDate;
+import java.time.temporal.TemporalField;
+import java.time.temporal.WeekFields;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * DateExtractFunction
+ * description:
+ * - year(date)--returns the year from SQL date date
+ * - quarter(date)--returns the quarter of a year (an integer between 1 and 4) from SQL date date
+ * - month(date)--returns the month of a year (an integer between 1 and 12) from SQL date date
+ * - week(date)--returns the week of a year (an integer between 1 and 53) from SQL date date
+ * - dayofyear(date)--returns the day of a year (an integer between 1 and 366) from SQL date date
+ * - dayofmonth(date)--returns the day of a month (an integer between 1 and 31) from SQL date date
+ */
+public class DateExtractFunction implements ValueParser {
+
+    private int type;
+    private ValueParser dateParser;
+    private static final TemporalField weekOfYearField = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
+
+    /**
+     * Constructor
+     *
+     * @param type the type of date extract function(1->year, 2->quarter, 3->month, 4->week, 5->dayofyear, 6->dayofmonth)
+     * @param expr
+     */
+    public DateExtractFunction(int type, Function expr) {
+        this.type = type;
+        List<Expression> expressions = expr.getParameters().getExpressions();
+        dateParser = OperatorTools.buildParser(expressions.get(0));
+    }

Review Comment:
   fixed.



-- 
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-10764][SDK] Transform SQL support temporal functions(Including year, quarter, month, week, dayofyear and dayofmonth) [inlong]

Posted by "aloyszhang (via GitHub)" <gi...@apache.org>.
aloyszhang commented on code in PR #10766:
URL: https://github.com/apache/inlong/pull/10766#discussion_r1710575837


##########
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/DateExtractFunction.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.sql.Date;
+import java.time.LocalDate;
+import java.time.temporal.TemporalField;
+import java.time.temporal.WeekFields;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * DateExtractFunction
+ * description:
+ * - year(date)--returns the year from SQL date date
+ * - quarter(date)--returns the quarter of a year (an integer between 1 and 4) from SQL date date
+ * - month(date)--returns the month of a year (an integer between 1 and 12) from SQL date date
+ * - week(date)--returns the week of a year (an integer between 1 and 53) from SQL date date
+ * - dayofyear(date)--returns the day of a year (an integer between 1 and 366) from SQL date date
+ * - dayofmonth(date)--returns the day of a month (an integer between 1 and 31) from SQL date date
+ */
+public class DateExtractFunction implements ValueParser {
+
+    private int type;
+    private ValueParser dateParser;
+    private static final TemporalField weekOfYearField = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
+
+    /**
+     * Constructor
+     *
+     * @param type the type of date extract function(1->year, 2->quarter, 3->month, 4->week, 5->dayofyear, 6->dayofmonth)
+     * @param expr
+     */
+    public DateExtractFunction(int type, Function expr) {
+        this.type = type;
+        List<Expression> expressions = expr.getParameters().getExpressions();
+        dateParser = OperatorTools.buildParser(expressions.get(0));
+    }

Review Comment:
   Why not use meaningful words to represent the type like "YEAR", "MONTH"?
   int type value of 1,2,3,4,5 is understandable to users.
   



-- 
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