hutiefang76 commented on issue #13361:
URL: https://github.com/apache/seatunnel/issues/13361#issuecomment-7093938190
Here is the standalone probe from the precision-override experiment. I reran
it against `org.apache.seatunnel:seatunnel-shade-calcite:1.38.0-3.0.1`.
Save this as `CalciteTimestampCarrierProbe.java`.
```java
import
org.apache.seatunnel.shade.org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import
org.apache.seatunnel.shade.org.apache.calcite.rel.type.RelDataTypeSystemImpl;
import org.apache.seatunnel.shade.org.apache.calcite.sql.type.SqlTypeName;
import org.apache.seatunnel.shade.org.apache.calcite.util.TimestampString;
public class CalciteTimestampCarrierProbe {
private static boolean target(SqlTypeName t) {
return t == SqlTypeName.TIMESTAMP || t ==
SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE;
}
public static void main(String[] args) {
JavaTypeFactoryImpl vanilla = new JavaTypeFactoryImpl();
JavaTypeFactoryImpl precisionSix = new JavaTypeFactoryImpl(new
RelDataTypeSystemImpl() {
@Override
public int getMaxPrecision(SqlTypeName t) {
return target(t) ? 6 : super.getMaxPrecision(t);
}
});
for (SqlTypeName name : new SqlTypeName[] {SqlTypeName.TIMESTAMP,
SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE}) {
var normal = vanilla.createSqlType(name, 6);
var six = precisionSix.createSqlType(name, 6);
var nullable = precisionSix.createTypeWithNullability(six, true);
System.out.printf("%s requested=6 default-max=%d
default-actual=%d custom-actual=%d required=%s nullable=%s%n",
name, vanilla.getTypeSystem().getMaxPrecision(name),
normal.getPrecision(), six.getPrecision(),
precisionSix.getJavaClass(six).getTypeName(),
precisionSix.getJavaClass(nullable).getTypeName());
if (six.getPrecision() != 6 || precisionSix.getJavaClass(six) !=
long.class
|| precisionSix.getJavaClass(nullable) != Long.class) {
throw new AssertionError("Unexpected timestamp projection
carrier");
}
}
TimestampString first = new TimestampString("2024-06-15
16:30:10.123456");
TimestampString second = new TimestampString("2024-06-15
16:30:10.123789");
System.out.printf("distinct TimestampString order=%d, physical
milliseconds=%d/%d%n",
first.compareTo(second), first.getMillisSinceEpoch(),
second.getMillisSinceEpoch());
if (first.compareTo(second) >= 0 || first.getMillisSinceEpoch() !=
second.getMillisSinceEpoch()) {
throw new AssertionError("Expected collision when converting the
distinct literals");
}
}
}
```
```sh
mvn -q dependency:get
-Dartifact=org.apache.seatunnel:seatunnel-shade-calcite:1.38.0-3.0.1
jar="$HOME/.m2/repository/org/apache/seatunnel/seatunnel-shade-calcite/1.38.0-3.0.1/seatunnel-shade-calcite-1.38.0-3.0.1.jar"
javac -cp "$jar" CalciteTimestampCarrierProbe.java
java -cp "$jar:." CalciteTimestampCarrierProbe
```
Output from my rerun:
```text
TIMESTAMP requested=6 default-max=3 default-actual=3 custom-actual=6
required=long nullable=java.lang.Long
TIMESTAMP_WITH_LOCAL_TIME_ZONE requested=6 default-max=3 default-actual=3
custom-actual=6 required=long nullable=java.lang.Long
distinct TimestampString order=-3, physical
milliseconds=1718469010123/1718469010123
```
The probe exercises Calcite's type factory and literal-to-millisecond
conversion. I will keep #13361 blocked on
[CALCITE-5266](https://issues.apache.org/jira/browse/CALCITE-5266) and use the
direct-engine and FakeSource matrices once the bundled runtime can preserve the
two values. Prepared with Codex assistance.
--
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]