JingsongLi commented on code in PR #10675: URL: https://github.com/apache/paimon/pull/10675#discussion_r4491959669
########## paimon-python/pypaimon/schema/default_value.py: ########## @@ -0,0 +1,337 @@ +# 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. + +"""Validate a scalar column default before it is stored. + +The stored value is still the original string. Scalar checks follow the Java +string casts used by ``DefaultValueUtils`` for booleans, numbers, dates, times +and timestamps. ARRAY, MAP and ROW defaults are accepted by Java's +``StringToArrayCastRule``, ``StringToMapCastRule`` and ``StringToRowCastRule``; +Python does not parse those forms yet and rejects them explicitly. +""" + +import re +from calendar import monthrange +from datetime import time +from typing import Optional + +from pypaimon.schema.data_types import AtomicType + +_TRUE = {"t", "true", "y", "yes", "1"} +_FALSE = {"f", "false", "n", "no", "0"} +_INT_MIN = -2147483648 +_INT_MAX = 2147483647 +_INT_RANGES = { + "TINYINT": (-128, 127), + "SMALLINT": (-32768, 32767), + "INT": (_INT_MIN, _INT_MAX), + "INTEGER": (_INT_MIN, _INT_MAX), + "BIGINT": (-9223372036854775808, 9223372036854775807), +} +_INTEGRAL = set(_INT_RANGES) +_APPROXIMATE = {"FLOAT", "DOUBLE"} +_CHARACTER = {"STRING", "CHAR", "VARCHAR"} +_BINARY = {"BINARY", "VARBINARY", "BYTES"} +_UNSIGNED_INTEGER_RE = re.compile(r"[0-9]+") +# StringUtils.isNumeric guards the epoch fast path of DATE, TIME and TIMESTAMP. +# It allows a leading '-' but not '+', and only ASCII digits after it. +_JAVA_NUMERIC_RE = re.compile(r"-?[0-9]+") +_INTEGRAL_RE = re.compile(r"[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]*)") +# BigDecimal(String) reads digits with Character.digit, so Unicode digits are +# valid here, unlike the other numeric casts. +_DECIMAL_RE = re.compile( + r"[+-]?(?:(\d+)(?:\.(\d*))?|\.(\d+))(?:[eE]([+-]?\d+))?") Review Comment: [P2] Reject decimal digits unsupported by the target JVM before committing Python `\d` and `int()` recognize a broader digit set than Java BigDecimal’s UTF-16 `Character.digit(char, 10)` parsing. For a DECIMAL(10,2) column, `UpdateColumnDefaultValue(["amount"], "𝟙")` succeeds and publishes schema-1, but reopening that exact schema and calling the Java batch writer’s `newWrite()` throws `NumberFormatException` while initializing defaults. `෧` (U+0DE7) also passes Python but fails on the supported JDK 8. This stops writer creation before any row can be supplied. Actual Python-schema-to-Java-writer probes reproduce both failures. ASCII `1`, valid BMP Arabic `١.٢`, and clearing the default with `None` all write and read back successfully. Please validate the decimal digit grammar against the target JVM’s supported characters before persisting, with JDK 8 interoperability coverage; simply accepting every Python Unicode decimal digit is not equivalent to the Java cast. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
