You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "xuzifu666 (via GitHub)" <gi...@apache.org> on 2024/07/30 12:54:23 UTC
[PR] [core] Support TimestampToNumericPrimitiveCastRule in casing [paimon]
xuzifu666 opened a new pull request, #3854:
URL: https://github.com/apache/paimon/pull/3854
<!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
### Purpose
Follow up https://github.com/apache/paimon/pull/3832 had support Timestamp to NumericPrimitive casting,this pr support NumericPrimitive to Timestamp casting.
<!-- Linking this pull request to the issue -->
Linked issue: close #xxx
<!-- What is the purpose of the change -->
### Tests
<!-- List UT and IT cases to verify this change -->
### API and Format
<!-- Does this change affect API or storage format -->
### Documentation
<!-- Does this change introduce a new feature -->
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 closed pull request #3854: [core] Support TimestampToNumericPrimitiveCastRule in casting
URL: https://github.com/apache/paimon/pull/3854
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1705002564
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * @link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
Review Comment:
@JingsongLi Thanks, had added case for target type.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 closed pull request #3854: [core] Support TimestampToNumericPrimitiveCastRule in casting
URL: https://github.com/apache/paimon/pull/3854
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #3854:
URL: https://github.com/apache/paimon/pull/3854
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1713107306
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * {@link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
+ } else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
+ return value ->
+ DateTimeUtils.unixTimestamp(
Review Comment:
Make sense,due to the number is hundreds million at least that Interge.Max also cannot hold the size,so I change to just handle Bigint condition in targetType and others return null. @JingsongLi
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1704876929
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * @link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
Review Comment:
Please add a case cast to and cast from.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1713113617
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * {@link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
+ } else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
+ return value ->
+ DateTimeUtils.unixTimestamp(
Review Comment:
And `CastRulePredicate` should be only target to int and bigint
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1705002564
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * @link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
Review Comment:
@JingsongLi Thanks, had added case for target type.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1713114268
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * {@link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
+ } else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
+ return value ->
+ DateTimeUtils.unixTimestamp(
Review Comment:
Yes,should support int and bigint,I would change it latter. Thanks for the reminder. @JingsongLi
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1713107306
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * {@link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
+ } else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
+ return value ->
+ DateTimeUtils.unixTimestamp(
Review Comment:
Make sense,due to the number is hundreds million at least that Interge.Max also cannot hold the size,so I change to just handle Bigint condition and others return null. @JingsongLi
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1713107306
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * {@link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
+ } else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
+ return value ->
+ DateTimeUtils.unixTimestamp(
Review Comment:
Make sense,due to the number is hundreds million at least that Interge.Max also cannot hold the size,so I just handle Bigint condition and others return null. @JingsongLi
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1713113227
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * {@link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
+ } else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
+ return value ->
+ DateTimeUtils.unixTimestamp(
Review Comment:
integer is OK?
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 closed pull request #3854: [core] Support TimestampToNumericPrimitiveCastRule in casting
URL: https://github.com/apache/paimon/pull/3854
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "xuzifu666 (via GitHub)" <gi...@apache.org>.
xuzifu666 commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1709300877
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * @link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
Review Comment:
OK,had added cast to and from in test case @JingsongLi
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [core] Support TimestampToNumericPrimitiveCastRule in casting [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #3854:
URL: https://github.com/apache/paimon/pull/3854#discussion_r1713008720
##########
paimon-core/src/main/java/org/apache/paimon/casting/TimestampToNumericPrimitiveCastRule.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.paimon.casting;
+
+import org.apache.paimon.data.Timestamp;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypeFamily;
+import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.utils.DateTimeUtils;
+
+/**
+ * {@link DataTypeRoot#TIMESTAMP_WITHOUT_TIME_ZONE}/{@link
+ * DataTypeRoot#TIMESTAMP_WITH_LOCAL_TIME_ZONE} to {@link DataTypeFamily#NUMERIC} cast rule.
+ */
+public class TimestampToNumericPrimitiveCastRule extends AbstractCastRule<Timestamp, Number> {
+
+ static final TimestampToNumericPrimitiveCastRule INSTANCE =
+ new TimestampToNumericPrimitiveCastRule();
+
+ private TimestampToNumericPrimitiveCastRule() {
+ super(
+ CastRulePredicate.builder()
+ .input(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)
+ .input(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .target(DataTypeFamily.NUMERIC)
+ .build());
+ }
+
+ @Override
+ public CastExecutor<Timestamp, Number> create(DataType inputType, DataType targetType) {
+ if (inputType.is(DataTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE)) {
+ return value -> DateTimeUtils.unixTimestamp(value.getMillisecond());
+ } else if (inputType.is(DataTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
+ return value ->
+ DateTimeUtils.unixTimestamp(
Review Comment:
For int, short, byte types, should not return long.
--
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: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org