ISSUE DESCRIPTION [SQL] "expand" projection is always named "value" ignoring "AS"…
- User
ISSUE DESCRIPTION
[SQL] "expand" projection is always named "value" ignoring "AS"
ArcadeDB Server v26.5.1 (build b6d08fee549dd5930303b362223869901aab0fac/1778533954349/main)Running on Linux 6.17.0-29-generic - OpenJDK 64-Bit Server VM 25.0.3-eaUsing
expandin a projection, the result-set contains an property namedvalueinspite an alias of the formAS x:sqlSELECT expand([1,2,3,4]) AS testresults in:
json{"result":[{"value":1},{"value":2},{"value":3},{"value":4}]}ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
- Assistant
I’ll first map the SQL projection/execution code and locate existing
expandtests, then reproduce the alias behavior with the narrowest relevant test suite before changing implementation. - Assistant
ripgrepis unavailable, so I’ll usegrepto identify the parser/executor classes and tests that mentionexpand. - Assistant
The issue sits at the boundary between projection aliasing and
ExpandStep: map/document elements are flattened as records, while primitive elements are wrapped. I’ll inspect those classes and the existing regression-focusedExpandParseTestto determine where the alias is currently discarded. - Assistant
ExpandStepalready extracts the sole projected property name (propName), which is the explicit alias when one is supplied, but then hardcodes"value"for scalar elements. The likely minimal fix is to retain that name for the active subsequence and use it when wrapping scalars. Before editing, I’ll confirm projection naming and run the existing test with a temporary JShell impractical; easiest is Maven test plus a tiny temporary JUnit-free Java path, but the current test can be augmented only temporarily then reverted. Instead I’ll inspect module test setup and relevant projection methods first. - Assistant
There are two losses:
ProjectionItem.getExpandContent()drops the explicit alias before projection calculation, and scalar wrapping hardcodes"value". Simply usingpropNamewould also change legacy no-alias output from"value"to the expression text, so the implementation should preserve backward compatibility: carry the explicit alias into the rewritten projection, then haveExpandStepuse it only when explicit, otherwise"value". I’ll inspect planner data flow and constructors/copy methods to choose a clean way to pass that distinction. - Assistant
The planner rewrites the projection before constructing
ExpandStep, but the rewritten item can retain its nullable explicit alias. I’ll add a nullable scalar alias toExpandStep, pass it from the rewritten projection, and preserve the alias ingetExpandContent(). This isolates behavior to scalar wrapping: maps/documents/results remain flattened exactly as before, explicit aliases name primitive outputs, and unaliased primitives remain"value". I’ll first run the current targeted test as a baseline/reproduction proxy, then use a temporary standalone test class only if needed. - Assistant
The Maven wrapper requires
HOMEin this environment. I’ll rerun with a temporary home setting; after compilation, I can reproduce the exact query via JShell using the engine test/runtime classpath without touching repository tests. - Assistant
The baseline targeted suite passes, confirming no existing assertion covers scalar aliasing. I’ll now run the reported query against a temporary database with a
/tmpJava program and Maven-generated test classpath, recording property names before the fix. - Assistant
The exact reproduction outputs
[value]four times. I’ll implement the two-part fix now: preserve the parsed alias during expand projection rewriting, and pass that explicit alias toExpandStepfor scalar rows while keeping the existing constructor/default behavior for compatibility. - Assistant
Python is not installed, so no files were changed. I’ll apply the same small edits using the repository’s
edithelper after locating exact line numbers. - Assistant
I’ll edit the three exact regions: constructor/state, scalar property assignment, and planner alias extraction plus alias preservation.
- Assistant
The diff is narrow and preserves unaliased behavior. I’ll compile and rerun the exact reproduction, extending it to verify both explicit alias and legacy no-alias output, plus a quoted alias edge case.
- Assistant
The reproduction is fixed: aliased scalars now expose
test, unaliased scalars still exposevalue, and quoted aliases resolve correctly. I’ll run the focused expand parser/executor suites to cover maps/documents, collections, empty/null values, limits, nested projections, and unwind interactions. - Assistant
All 35 focused tests pass. I’ll do a final review for formatting, generated/build artifacts, and unintended changes. I’ll also consider whether alias objects should be copied during AST rewriting; since other rewrite methods copy mutable identifiers, I’ll inspect conventions before finalizing.
- Assistant
Only the intended three source files are modified. To follow parser-copy conventions and avoid sharing a mutable
Identifierbetween original and rewritten projections, I’ll preserve a copy of the alias rather than the same object, then run the engine’s validation phase (or at least checkstyle/compile if broader validation is expensive). - Assistant
The helper did not apply the copy refinement because the file was not active at the start of the compound command; validation itself succeeded but only exercised the
validatelifecycle. I’ll apply the one-line refinement now, then runtestwithout skipping style checks so normal lifecycle checks execute alongside the focused tests. - Assistant
The normal focused test lifecycle passes after the final refinement (35/35). Final checklist review:
- Reported error reproduced: Yes. The temporary
/tmp/Repro.javaranSELECT expand([1,2,3,4]) AS testbefore changes and printed[value]for every row. - Fix confirmed: Yes. The same reproduction after changes printed
[test]:1through[test]:4. - Edge cases considered: Yes. I verified unaliased scalar expansion remains
[value], quoted aliases work, and existing map/document/nested-projection behavior remains covered. Scalar aliasing is intentionally applied only to wrapped primitive values; expanded maps/results/documents continue to expose their own fields. - Affected existing tests run: Yes.
ExpandParseTest,ExpandStepTest,UnwindExpandStepTest, andProjectionTestall pass, totaling 35 tests. The module compiles successfully andgit diff --checkis clean.
I’ll perform one final diff/status inspection to ensure the submission contains only the intended source changes, then submit.
- Reported error reproduced: Yes. The temporary
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.