Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ pub async unsafe fn execute_indexed_with_context(
let (segments, schema) = build_segments(&state, Arc::clone(&store), object_metas.as_ref(), writer_generations.as_ref())
.await
.map_err(DataFusionError::Execution)?;
let schema = crate::schema_coerce::coerce_inferred_schema(schema);
for (i, seg) in segments.iter().enumerate() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ public class DataFusionAnalyticsBackendPlugin implements AnalyticsSearchBackendP
// see a real time/date type and Isthmus serializes accordingly.
ScalarFunction.TIME,
ScalarFunction.DATE,
ScalarFunction.TIMESTAMP,
// PPL `datetime(expr)` — parse/cast into a TIMESTAMP. Routes to DF's
// builtin `to_timestamp` via DatetimeAdapter. The single-arg
// `timestamp(expr)` form shares these semantics but its ScalarFunction
// slot is already bound to TimestampFunctionAdapter for VARCHAR literal
// folding, so it stays on the legacy engine.
// builtin `to_timestamp` via DatetimeAdapter.
ScalarFunction.DATETIME,
// PPL extract / make* / format / from_unixtime are implemented as Rust UDFs
// to preserve MySQL semantics that DataFusion builtins don't match: EXTRACT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ final class DatetimeOutputCastRewriter {
/**
* PPL's documented timestamp output format (space separator). Mirrors the
* format used by Calcite's reference planner so the analytics-engine path
* matches per-row output exactly.
* matches per-row output exactly. The trailing {@code %.f} is chrono's
* variable-length fractional-second specifier — a leading dot followed by
* 0-9 digits, omitted when the value has no sub-second precision. This
* matches PPL's legacy formatting for {@code date} and {@code date_nanos}
* fields where the displayed precision tracks the source value (e.g.
* {@code "2024-01-15 10:30:01.23456789"} for a date_nanos with 8 fractional
* digits, {@code "2025-08-01 03:47:41"} for a whole-second value).
*/
static final String PPL_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S";
static final String PPL_TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S%.f";

private DatetimeOutputCastRewriter() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ public void setUp() throws Exception {

/**
* Motivating shape: outer Project slot is exactly {@code CAST(<TIMESTAMP> AS VARCHAR)}.
* Rewriter must replace it with a {@code TO_CHAR(<TIMESTAMP>, '%Y-%m-%d %H:%M:%S')}
* call whose result type matches the original cast's VARCHAR type.
* Rewriter must replace it with a {@code TO_CHAR(<TIMESTAMP>, '%Y-%m-%d %H:%M:%S%.f')}
* call whose result type matches the original cast's VARCHAR type. The {@code %.f}
* tail is chrono's variable-length fractional-seconds specifier so source values
* with sub-second precision (DATE_NANOS) keep their fractional digits while
* whole-second values display cleanly without a trailing decimal.
*/
public void testDirectTimestampOutputCastIsRewrittenToToChar() {
RelDataType timestampType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 6), true);
Expand Down Expand Up @@ -236,11 +239,11 @@ public void testTimestampCastToCharIsUntouched() {
}

/**
* The format string is {@code "%Y-%m-%d %H:%M:%S"} — seconds-only — to match
* Calcite's reference output for {@code CAST(TIMESTAMP AS VARCHAR)}, which
* truncates fractional seconds. This pins that contract: a TIMESTAMP(9)
* source still resolves to the seconds-only format literal in the
* rewritten {@code TO_CHAR} call.
* The format string is precision-agnostic: a TIMESTAMP(0) and a TIMESTAMP(9)
* source both resolve to the same {@code "%Y-%m-%d %H:%M:%S%.f"} literal in the
* rewritten {@code TO_CHAR} call. The {@code %.f} tail handles the runtime
* variation — whole-second values render without a trailing decimal, sub-second
* values render with as many fractional digits as the source carries.
*/
public void testTimestampPrecisionDoesNotChangeFormat() {
RelDataType nanoTimestampType = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.TIMESTAMP, 9), true);
Expand All @@ -255,7 +258,7 @@ public void testTimestampPrecisionDoesNotChangeFormat() {
RexCall call = (RexCall) ((LogicalProject) rewritten).getProjects().get(0);
RexLiteral formatLit = (RexLiteral) call.getOperands().get(1);
assertEquals(
"TIMESTAMP(9) source must still resolve to the seconds-only format — fractional seconds are dropped",
"Format literal is precision-agnostic — chrono's %.f handles the per-value fractional digits",
DatetimeOutputCastRewriter.PPL_TIMESTAMP_FORMAT,
formatLit.getValueAs(String.class)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ public void execute(RelNode logicalFragment, Object context, ActionListener<Iter
executeInternal(logicalFragment, listener);
} catch (Exception e) {
listener.onFailure(e);
} catch (AssertionError e) {
Comment thread
mch2 marked this conversation as resolved.
Resolved
// Calcite's Litmus.THROW (used by RelOptUtil.eq, RexUtil.isFlat, Project.isValid,
// RexChecker) throws AssertionError directly via Java code rather than via the
// `assert` keyword, so JVM -da doesn't gate them. If one fires inside this
// executor, OpenSearchUncaughtExceptionHandler exits the cluster JVM. Convert to
// an IllegalStateException so the query path treats it as a per-query failure
// (HTTP 500 with a bucketable message) instead of cluster-fatal.
listener.onFailure(new IllegalStateException("Analytics-engine executor rejected the plan: " + e.getMessage(), e));
}
});
}
Expand Down
Loading