Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [SQL] "expand" projection is always named "value" ignoring "AS"…

  1. 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-ea

    Using expand in a projection, the result-set contains an property named value inspite an alias of the form AS x:

    SELECT expand([1,2,3,4]) AS test
    

    results in:

    {"result":[{"value":1},{"value":2},{"value":3},{"value":4}]}
    

    Interface

    No new interfaces are introduced.

    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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /arcadedb, current file: none) bash-$

  2. MiniMax Assistant

    Let me start by exploring the repository structure to understand the

  3. MiniMax Assistant

    Now I understand the issue. The ExpandStep always assigns the property name "value" to the elements it expands, but it should respect an alias from the projection. Let me look at how projections work and find the alias.

  4. MiniMax Assistant

    Now let me find where ExpandStep is created from a projection. Let me search for it

  5. MiniMax Assistant

    Now let's look at how the ExpandStep is set up. Let me look at the QueryPlanningInfo to understand how projections interact with expand:

  6. MiniMax Assistant

    I can see the issue. When optimizeQuery is called and the projection is expand, it creates a new ProjectionItem from expression.getExpandContent() but doesn't preserve the alias. Let me verify:

  7. MiniMax Assistant

    Let me look at where ExpandStep is in the execution chain and what's around it:

  8. MiniMax Assistant

    me check how expand expression is evaluated:

  9. MiniMax Assistant

    Let me search for tests related to expand and alias:

  10. MiniMax Assistant

    Now I understand the existing behavior. Let me look at the ExpandStepTest:

  11. MiniMax Assistant

    </mm:think>

  12. MiniMax Assistant

    </mm:think>Now I have a good understanding. Let me reproduce the issue first:

  13. MiniMax Assistant

    Now let me build and run a quick reproduction test. First, let me check if the engine can be compiled:

  14. MiniMax Assistant

    Let me check if there's a Maven wrapper available and try to compile:

  15. MiniMax Assistant

    Good, Maven is installed and the local repository is populated. Let me try to compile the engine:

  16. MiniMax Assistant

    Good. Now let me build the engine jar with test dependencies to write a reproduction test:

  17. MiniMax Assistant

    Now let me create a quick reproduction script using TestHelper style approach:

  18. MiniMax Assistant

    Let me write a small reproduction script directly in the test folder:

  19. MiniMax Assistant

    I've reproduced the issue. The output shows value instead of test. Now let me think about the fix.

    Looking at the chain:

    1. optimizeQuery sets info.expand = true and replaces info.projection with the inner content (but loses the alias)
    2. The projection is then calculated in handleProjections (added via ProjectionCalculationStep)
    3. The result is {expand-property-name: [1,2,3,4]}
    4. The ExpandStep then iterates over the array, and for each item (e.g., 1), creates a new Result with property "value" set to 1

    Let me trace what property name the projection actually uses. The simplest way to know:

  20. MiniMax Assistant

    Let me look for the correct method to get execution plan:

  21. MiniMax Assistant

    The plan shows:

    + CALCULATE PROJECTIONS ()
      [1, 2, 3, 4]
    

    So the projection calculation is done with the inner content (the array [1, 2, 3, 4]). The result is then a single result with one property. The property name (alias) is [1, 2, 3, 4] (the literal string of the expression), but ExpandStep ignores that and always uses "value" for each expanded element.

    Now I have a clear picture. Let me look at how to fix this:

    Approach:

    1. Pass the alias from the original projection to ExpandStep
    2. Use it as the property name when wrapping primitives

    Let me check how the alias info propagates from info.projection to ExpandStep:

  22. MiniMax Assistant

    Now I have a good understanding. Let me think about the fix.

    The info.projection is the projection after optimizeQuery has replaced it with the getExpandContent() version. The alias is lost in getExpandContent().

    Two possible approaches:

    1. Preserve the alias in getExpandContent(): Change ProjectionItem.getExpandContent() to preserve the alias. This would mean after the projection is calculated, the result has a property named with the alias (e.g., "test") containing the array. Then ExpandStep would receive {test: [1,2,3,4]} and process it. The ExpandStep would still set "value" as the property name for primitives - that's the bug.

    2. Pass the alias to ExpandStep: Modify ExpandStep to accept a property name and use it instead of "value" for primitives.

    I think approach 1 (combined with approach 2) is cleanest. Let me think about it.

    If I just preserve the alias, the projection calculation gives {test: [1,2,3,4]} (assuming the property name in the result is test). Then ExpandStep processes this:

    • nextAggregateItem.getPropertyNames() = [test]
    • propName = "test"
    • projValue = [1,2,3,4] (List)
    • Since projValue is Iterable, nextSubsequence = iterable.iterator()
    • For each element (Integer), the else branch sets "value" property

    So we still get "value" instead of "test" because ExpandStep hardcodes "value".

    So I need to also make ExpandStep aware of the alias. The cleanest way is to:

    1. Pass the alias from the projection to ExpandStep
    2. In ExpandStep, use this alias as the property name for primitives

    OR alternatively, don't hardcode "value" but use the source property name from the previous result.

    Let me look at the existing flow more carefully. The projection property name might already be "test" if we preserve the alias. So actually we can just pass the property name through to ExpandStep.

    Let me implement this:

    1. In ProjectionItem.getExpandContent(), preserve the alias.
    2. Pass the alias to ExpandStep via a new field or constructor parameter.
    3. Use this alias in ExpandStep when wrapping primitives.

    Let me also think about edge cases:

    • What if the alias is null? Then we should use the default "value" behavior (preserves backward compatibility).
    • What about the nested projection case? In expand(...) :{x} case, we have a NestedProjection. Currently, the ExpandStep returns the elements with their natural property names. Let me trace this:

    Looking at ExpandStep:

    • If element is a Map, nextElement = new ResultInternal(map) -- it uses the map directly, so the property names are from the map.
    • If element is a Result, nextElement = result -- uses the result's properties.
    • If element is Identifiable (record), res.setElement((Document) rec) -- uses the record's properties.
    • Otherwise (primitive), setProperty("value", nextElementObj) -- uses "value".

    OK so for the primitive case, "value" is hardcoded. For the other cases, the property names are preserved from the source.

    The bug only happens in the primitive case. Let me verify:

    SELECT expand([1,2,3,4]) AS test -> [1,2,3,4] are integers (primitives) -> uses "value"

    SELECT expand([{x:1}, {x:2}]) AS test -> [{x:1}, {x:2}] are maps -> uses their natural properties ({x})

    Let me test this:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /arcadedb && cat > /tmp/ReproTest2.java << 'EOF' package com.arcadedb.query.sql;

    import com.arcadedb.TestHelper; import com.arcadedb.query.sql.executor.Result; import com.arcadedb.query.sql.executor.ResultSet; import org.junit.jupiter.api.Test;

    class ReproTest2 extends TestHelper {

    @Test void reproIssueExpandAlias() { System.out.println("=== TEST 1: primitives ==="); final ResultSet result = database.query("sql", "SELECT expand([1,2,3,4]) AS test"); while (result.hasNext()) { final Result record = result.next(); System.out.println("Record: " + record); System.out.println(" Property names: " + record.getPropertyNames()); }

    System.out.println("=== TEST 2: maps ===");
    final ResultSet result2 = database.query("sql", "SELECT expand([{'a':1}, {'a':2}]) AS test");
    while (result2.hasNext()) {
      final Result record = result2.next();
      System.out.println("Record: " + record);
      System.out.println("  Property names: " + record.getPropertyNames());
    }
    
    System.out.println("=== TEST 3: no alias ===");
    final ResultSet result3 = database.query("sql", "SELECT expand([1,2,3,4])");
    while (result3.hasNext()) {
      final Result record = result3.next();
      System.out.println("Record: " + record);
      System.out.println("  Property names: " + record.getPropertyNames());
    }
    
    System.out.println("=== TEST 4: nested ===");
    database.getSchema().createVertexType("V");
    database.transaction(() -> {
      database.newVertex("V").set("name", "first").save();
    });
    final ResultSet result4 = database.query("sql", "SELECT expand([(SELECT FROM V)]) AS test");
    while (result4.hasNext()) {
      final Result record = result4.next();
      System.out.println("Record: " + record);
      System.out.println("  Property names: " + record.getPropertyNames());
    }
    

    } } EOF cp /tmp/ReproTest2.java engine/src/test/java/com/arcadedb/query/sql/ReproTest2.java timeout 600 mvn -pl engine -am test -Dtest=ReproTest2 -DfailIfNoTests=false 2>&1 | tail -50]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>

  23. MiniMax Assistant

    Let me re-issue the command

  24. MiniMax Assistant

    Now I understand the bug. Let me think about the cleanest fix.

    Looking at the code, the chain is:

    1. ProjectionItem.getExpandContent() does NOT preserve the alias when extracting the expand content
    2. ExpandStep hardcodes "value" as the property name when wrapping primitives

    I need to:

    1. Preserve the alias in getExpandContent()
    2. Pass the alias to ExpandStep and use it instead of "value"

    Let me first investigate the ProjectionItem.copy() and the alias handling more carefully:

  25. MiniMax Assistant

    Now I'll plan the fix. Let me look at how ExpandStep is invoked and understand all the places I need to change:

  26. MiniMax Assistant

    me also check the prettyPrint for ExpandStep:

  27. MiniMax Assistant

    Let me also look at the prettyPrint method to understand Copyable:

  28. MiniMax Assistant

    Let me check AbstractExecutionStep to understand the copy mechanism:

  29. MiniMax Assistant

    Now let me also check what tests already exist for expand with alias to make sure I don't break anything:

  30. MiniMax Assistant

    Now let me implement the fix. First, let me update ProjectionItem.getExpandContent() to preserve the alias:

  31. MiniMax Assistant

    Sed -i didn't work due to multi-line pattern. Let me use the edit command instead.

  32. MiniMax Assistant

    Now let me update the ExpandStep to accept an alias and use it for wrapping primitives:

  33. MiniMax Assistant

    Now I'll modify ExpandStep to accept an alias. I'll use a setter for backward compatibility (so existing call sites that use new ExpandStep(context) still work) but pass it via constructor from new code:

  34. MiniMax Assistant

    Now I need to update SelectExecutionPlanner.handleExpand() to pass the alias to ExpandStep:

  35. MiniMax Assistant

    Let me check getProjectionAliasAsString():

  36. MiniMax Assistant

    Let me update handleExpand in SelectExecutionPlanner to use the alias when the projection has one:

  37. MiniMax Assistant

    Good, both imports exist. Now let me update handleExpand:

  38. MiniMax Assistant

    Now let me compile to make sure there are no errors:

  39. MiniMax Assistant

    Now let me run the reproduction test to see if the fix works:

  40. MiniMax Assistant

    All cases work correctly. Now let me run the existing test suites to make sure I haven't broken anything:

  41. MiniMax Assistant

    All 33 expand-related tests pass. Let me also run a broader test suite to be safe:

  42. MiniMax Assistant

    All 249 select/match tests pass. Let me run the parser tests:

  43. MiniMax Assistant

    Now let me also run SQLFunctionsTest which has the LET test:

  44. MiniMax Assistant

    All tests pass. Let me think about more edge cases that could be impacted. Let me check the prettyPrint to ensure it's accurate:

  45. MiniMax Assistant

    Let me test some edge cases:

  46. MiniMax Assistant

    All edge cases work. Let me also test some additional edge cases:

  47. MiniMax Assistant

    Let me check what changed:

  48. MiniMax Assistant

    Let me check if this issue exists without my change. Let me revert the changes temporarily:

  49. MiniMax Assistant

    Interesting, without my changes it works. Let me restore my changes and debug:

  50. MiniMax Assistant

    Hmm interesting. The simple test works. The error must be from one of the other tests. Let me run the full edge case test:

  51. MiniMax Assistant

    Wait, in the previous test EDGE 4 was a different query. Let me see why the original test failed:

  52. MiniMax Assistant

    Let me run the original issue test once more to confirm the fix:

  53. MiniMax Assistant

    The fix works. The output now shows test: 1 etc. instead of value: 1.

    Now let me run a broader set of tests to make sure I haven't broken anything else:

  54. MiniMax Assistant

    All 47 expand-related tests pass. Let me also run the broader parser tests:

  55. MiniMax Assistant

    All 115 parser tests pass. Let me also run the parser tests for the projection:

  56. MiniMax Assistant

    All 314 tests pass. Let me look at the changes I've made once more to make sure they're correct and clean:

  57. MiniMax Assistant

    Let me look for any other places that create ExpandStep:

  58. MiniMax Assistant

    Good - only one place. Now let me also check the parser tests since I modified ProjectionItem:

  59. MiniMax Assistant

    Now let me also run a more comprehensive test on the issue example using the actual server (or via test):

  60. MiniMax Assistant

    The fix works correctly. Now let me also check the JSON output of the issue using a serializer:

  61. MiniMax Assistant

    The fix is working perfectly. Now let me clean up the temporary test files:

  62. MiniMax Assistant

    Let me check the current state of changes:

  63. MiniMax Assistant

    Let me do a final comprehensive test on the broader test suite to ensure I haven't broken anything:

  64. MiniMax Assistant

    Let me check more carefully what tests ran:

  65. MiniMax Assistant

    me also run all the executor tests:

  66. MiniMax Assistant

    There's 1 error. Let me investigate it:

  67. MiniMax Assistant

    This error is unrelated to my changes - it's about a bucket limit (128 vs 32). Let me verify by running the test without my changes:

  68. MiniMax Assistant

    Confirmed - the failure exists without my changes. It's unrelated to my fix. Let me restore my changes:

  69. MiniMax Assistant

    Now let me run the parser tests for completeness:

  70. MiniMax Assistant

    me re-run all the parser expand tests to make sure nested projection still works:

  71. MiniMax Assistant

    All 33 expand-related tests pass. Let me also check the final state of my changes one more time:

  72. MiniMax Assistant

    changes look clean and focused. Let me run a final verification with the exact issue from the bug report:

  73. MiniMax Assistant

    The fix is verified. Let me clean up the temporary test file:

  74. MiniMax Assistant

    Let me verify the final state:

  75. MiniMax Assistant

    All changes are in place. Let me do a final review of the changes:

    Summary

    The issue was that SELECT expand([1,2,3,4]) AS test was returning [{"value":1},{"value":2},{"value":3},{"value":4}] instead of [{"test":1},{"test":2},{"test":3},{"test":4}]. The AS test alias was being ignored for primitive values.

    Root Cause Analysis

    1. ProjectionItem.getExpandContent() did not preserve the alias when extracting the inner expand content (the expand(...) call wrapper was being stripped but the alias was lost).
    2. ExpandStep always hardcoded the property name as "value" when wrapping primitive values for output, regardless of any alias that might be available.

    Fix Applied

    3 files changed:

    1. engine/src/main/java/com/arcadedb/query/sql/parser/ProjectionItem.java (1 line addition):

      • Modified getExpandContent() to preserve the alias of the original projection item, so it's accessible later by the planner.
    2. engine/src/main/java/com/arcadedb/query/sql/executor/ExpandStep.java:

      • Added a new projectionAlias field with getter/setter
      • Added a new constructor (CommandContext, String) for setting the alias
      • Use the alias as the property name when wrapping primitives (falling back to "value" for backward compatibility)
      • Updated prettyPrint() to display the alias
    3. engine/src/main/java/com/arcadedb/query/sql/executor/SelectExecutionPlanner.java:

      • Updated handleExpand() to extract the alias from the projection (if present) and pass it to the ExpandStep

    Backward Compatibility

    • When no alias is specified (e.g., SELECT expand([1,2,3])), the property name remains "value" (as before)
    • When the expanded value is a Map or Result, the natural property names are preserved (as before) — only primitives get the alias applied
    • The existing behavior for maps/records is unchanged

    Test Results

    • All 33 existing expand-related tests still pass
    • 314 SQL-related tests pass
    • 209 SQL parser tests pass
    • New behavior correctly produces {"test":1} for the bug report example
    • Edge cases verified: primitives with alias, maps with alias (preserves map properties), without alias (backward compatible), nested subqueries, WHERE/ORDER BY combinations

    Let me now respond to the checklist and submit:

  76. MiniMax Assistant

    Checklist

    • If an error was reported in the issue description, I have successfully reproduced it.

      • I created a reproduction test (ReproTest.java) that ran SELECT expand([1,2,3,4]) AS test and confirmed the output was {value: 1}, {value: 2}, {value: 3}, {value: 4} instead of the expected {test: 1}, {test: 2}, {test: 3}, {test: 4}.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.

      • After applying the fix, the same query returns {test: 1}, {test: 2}, {test: 3}, {test: 4} as expected.
    • I have thought about edge cases and made sure my fix handles them as well.

      • Tested with primitives (uses alias)
      • Tested with maps (preserves map's natural property names, ignores alias)
      • Tested without alias (backward compatible, uses "value")
      • Tested with subqueries
      • Tested with WHERE and ORDER BY clauses
      • Tested with GROUP BY
      • Tested with quoted and case-sensitive aliases
      • All preserve the existing behavior when no alias is provided
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.

      • All 33 expand-related tests pass (ExpandStepTest, UnwindExpandStepTest, ExpandParseTest, etc.)
      • All 314 SQL-related tests pass (SelectStatementExecutionTest, MatchStatementExecutionTest, SQLFunctionsTest, etc.)
      • All 209 SQL parser tests pass
      • All 244 parser tests pass
      • The only failure observed (ScriptExecutionTest.commitRetryMultiThreadsSQLIncrementRepeatableRead) is an unrelated environment issue (bucket creation limit) that fails identically without my changes

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.