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 inspect the repository structure and search for the SQL
expandimplementation and existing projection tests. Then I’ll reproduce the alias behavior with the most focused available test harness, patch the result naming logic, and run the relevant tests plus edge-case checks. - Assistant
The behavior is implemented in the SQL execution pipeline. I found a dedicated
ExpandStep; I’ll inspect it together with planner construction and projection alias APIs, then locate the closest unit-test class that can execute a database-free literal query. - Assistant
ExpandStephardcodes"value"only when an expanded item is scalar; maps/documents intentionally retain their own fields. The alias is available on the single intermediate projection property but is discarded after reading it. ExistingExpandParseTestalready covers parsing an alias over a map, so I’ll inspect its expectations and the planner order to determine whether the scalar output should use the intermediate property name (which naturally carries explicit aliases and existing default behavior). - Assistant
The expand-content rewrite deliberately removes the outer alias, so blindly using the intermediate property name would rename unaliased scalar results to the expression text and would not fix the report. The safe design is to pass only the explicit alias into
ExpandStep, retaining"value"when noASis supplied. I’ll inspect the exact planner method and existing directExpandStepconstruction sites before changing its constructor/API. - Assistant
Only the planner constructs
ExpandStep. During initialization it detects and rewrites the projection, which is the right point to capture the explicit alias in planning state. I’ll inspectQueryPlanningInfoand initialization flow, then implement a nullable scalar alias: explicitASoverrides"value"for scalar elements, while maps,Results, and records continue expanding structurally as before. - Assistant
I’ll build the engine and run a small temporary Java reproducer from
/tmp(not adding or modifying repository tests) against the current code. It will print each row’s property names and values for both aliased and unaliased scalarexpand, establishing the baseline before the patch. - Assistant
The Maven wrapper requires
HOME, which is unset in this environment. I’ll rerun the same build/reproducer with a temporary home directory configured. - Assistant
The reproducer confirms the exact bug: aliased scalar rows are
[value] {value=…}, and unaliased rows also usevalue. I’ll now add planner state for the explicit expand alias, populate it before the projection rewrite, copy it when planning info is cloned, and letExpandStepuse it only for scalar wrappers. The existing constructor will remain as a compatibility overload defaulting to"value". - Assistant
Python is unavailable, so no files were changed. I’ll apply the same focused edits with the repository’s
edit/replacecommands and then inspect the diff. - Assistant
The
ExpandStepand planning-state edits applied, but the planner replacements did not because the editor command only considered its current displayed window despite the file option. I’ll open the two exact planner locations and edit them by line range. - Assistant
I have the exact line numbers now. I’ll replace the expand-detection block and constructor call directly, then compile and rerun the reproducer.
- Assistant
The implementation is complete and diff-clean. I’ll rebuild and rerun an expanded temporary reproducer covering: the reported alias, unaliased backward compatibility, a quoted/spaced alias, and map expansion (which must retain map fields rather than being wrapped under the alias).
- Assistant
The fix now produces
{test: …}for the reported query, preserves{value: …}withoutAS, supports quoted aliases, and leaves expanded maps structural. I’ll run the focused existingExpandParseTest, then a broader SQL executor test class likely to exercise projection/plan behavior. - Assistant
Implementation and verification are complete. Final review:
- Reported error reproduced: Yes. Before the change, the temporary
/tmpreproducer showedSELECT expand([1,2,3,4]) AS testreturning rows with[value] {value=…}. - Fix confirmed: Yes. The same reproducer now returns
[test] {test=…}for all four rows. - Edge cases considered: Yes. Unaliased scalar expansion still returns
value; quoted aliases such asAS `two words`work; expanded maps still expose their own fields (x,y) rather than being incorrectly wrapped; the original one-argumentExpandStepconstructor remains compatible; planning-state copies preserve the alias. - Affected existing tests run: Yes.
ExpandParseTestpassed 6/6 andSelectStatementExecutionTestpassed 157/157. The engine package also compiled successfully, andgit diff --checkreports no whitespace errors.
The final change captures an explicit projection alias before the planner rewrites , carries it through copied planning state, and uses it only when creates a scalar result wrapper. No test files were added or modified. I’ll submit the three source-file changes now.
- Reported error reproduced: Yes. Before the change, 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.