Skip to content

Commit 8cee0bb

Browse files
committed
fixing usage without AS n on map rojection returns
1 parent 82b00d0 commit 8cee0bb

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

pkg/cypher/executor.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,15 @@ func (e *StorageExecutor) parseReturnItems(returnPart string) []returnItem {
20202020
if asIdx > 0 {
20212021
item.expr = strings.TrimSpace(part[:asIdx])
20222022
item.alias = strings.TrimSpace(part[asIdx+4:])
2023+
} else {
2024+
// Handle map projection without AS alias: n { .*, key: value } -> column name is "n"
2025+
// Neo4j infers the column name from the variable before the map projection
2026+
if braceIdx := strings.Index(part, " {"); braceIdx > 0 {
2027+
varName := strings.TrimSpace(part[:braceIdx])
2028+
if varName != "" && !strings.Contains(varName, "(") {
2029+
item.alias = varName
2030+
}
2031+
}
20232032
}
20242033

20252034
items = append(items, item)

pkg/cypher/executor_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,32 @@ func TestParseReturnItemsMapProjectionWithAlias(t *testing.T) {
23142314
assert.Len(t, result.Rows, 1)
23152315
}
23162316

2317+
func TestParseReturnItemsMapProjectionWithoutAlias(t *testing.T) {
2318+
store := storage.NewMemoryEngine()
2319+
exec := NewStorageExecutor(store)
2320+
ctx := context.Background()
2321+
2322+
// Test that map projection syntax n { .*, key: value } WITHOUT AS alias
2323+
// Neo4j infers the column name from the variable before the map projection
2324+
params := map[string]interface{}{
2325+
"props": map[string]interface{}{
2326+
"name": "TestNode",
2327+
"value": float64(42),
2328+
"embedding": []float64{0.1, 0.2, 0.3},
2329+
},
2330+
}
2331+
2332+
result, err := exec.Execute(ctx, "CREATE (n:Node $props) RETURN n { .*, embedding: null }", params)
2333+
require.NoError(t, err)
2334+
2335+
// Should have exactly 1 column named "n" (inferred from variable)
2336+
assert.Len(t, result.Columns, 1, "Should have exactly 1 column, not split on comma inside {}")
2337+
assert.Equal(t, "n", result.Columns[0], "Column should be named 'n' inferred from variable before {}")
2338+
2339+
// Should have 1 row
2340+
assert.Len(t, result.Rows, 1)
2341+
}
2342+
23172343
func TestParseReturnItemsOrderByLimit(t *testing.T) {
23182344
store := storage.NewMemoryEngine()
23192345
exec := NewStorageExecutor(store)

0 commit comments

Comments
 (0)