Skip to content

Commit f5c28ac

Browse files
kyleconroyclaude
andcommitted
Add ROWSET_OPTIONS JSON normalization for OpenRowset bulk statements
- Add normalizeRowsetOptionsJSON function to normalize JSON strings - Normalize JSON by removing whitespace and uppercasing keys/values - Apply normalization in bulkInsertOptionToJSON for RowsetOptions - Enables OpenRowsetBulkStatementTests150 Also enables Baselines140_GraphDbSyntaxTests140 (graph match parsing now works) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 18ec952 commit f5c28ac

3 files changed

Lines changed: 75 additions & 3 deletions

File tree

parser/marshal.go

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17568,6 +17568,63 @@ func columnDefinitionBaseToJSON(c *ast.ColumnDefinitionBase) jsonNode {
1756817568
return node
1756917569
}
1757017570

17571+
// normalizeRowsetOptionsJSON normalizes a JSON string for ROWSET_OPTIONS
17572+
// by removing whitespace and uppercasing keys to match ScriptDOM behavior
17573+
func normalizeRowsetOptionsJSON(jsonStr string) string {
17574+
// Parse and re-serialize the JSON to normalize it
17575+
var data map[string]interface{}
17576+
if err := json.Unmarshal([]byte(jsonStr), &data); err != nil {
17577+
// If parsing fails, return as-is
17578+
return jsonStr
17579+
}
17580+
17581+
// Normalize keys to uppercase and values
17582+
normalized := normalizeJSONObject(data)
17583+
17584+
// Re-serialize without extra whitespace
17585+
result, err := json.Marshal(normalized)
17586+
if err != nil {
17587+
return jsonStr
17588+
}
17589+
return string(result)
17590+
}
17591+
17592+
// normalizeJSONObject recursively normalizes JSON object keys to uppercase
17593+
func normalizeJSONObject(data map[string]interface{}) map[string]interface{} {
17594+
result := make(map[string]interface{})
17595+
for k, v := range data {
17596+
upperKey := strings.ToUpper(k)
17597+
switch val := v.(type) {
17598+
case map[string]interface{}:
17599+
result[upperKey] = normalizeJSONObject(val)
17600+
case []interface{}:
17601+
result[upperKey] = normalizeJSONArray(val)
17602+
default:
17603+
result[upperKey] = v
17604+
}
17605+
}
17606+
return result
17607+
}
17608+
17609+
// normalizeJSONArray recursively normalizes JSON array values
17610+
func normalizeJSONArray(data []interface{}) []interface{} {
17611+
result := make([]interface{}, len(data))
17612+
for i, v := range data {
17613+
switch val := v.(type) {
17614+
case map[string]interface{}:
17615+
result[i] = normalizeJSONObject(val)
17616+
case []interface{}:
17617+
result[i] = normalizeJSONArray(val)
17618+
case string:
17619+
// Uppercase string values in arrays
17620+
result[i] = strings.ToUpper(val)
17621+
default:
17622+
result[i] = v
17623+
}
17624+
}
17625+
return result
17626+
}
17627+
1757117628
func bulkInsertOptionToJSON(opt ast.BulkInsertOption) jsonNode {
1757217629
switch o := opt.(type) {
1757317630
case *ast.BulkInsertOptionBase:
@@ -17581,7 +17638,23 @@ func bulkInsertOptionToJSON(opt ast.BulkInsertOption) jsonNode {
1758117638
"OptionKind": o.OptionKind,
1758217639
}
1758317640
if o.Value != nil {
17584-
node["Value"] = scalarExpressionToJSON(o.Value)
17641+
// For RowsetOptions, normalize the JSON string value
17642+
if o.OptionKind == "RowsetOptions" {
17643+
if strLit, ok := o.Value.(*ast.StringLiteral); ok {
17644+
normalizedValue := normalizeRowsetOptionsJSON(strLit.Value)
17645+
normalizedLit := &ast.StringLiteral{
17646+
LiteralType: strLit.LiteralType,
17647+
IsNational: strLit.IsNational,
17648+
IsLargeObject: strLit.IsLargeObject,
17649+
Value: normalizedValue,
17650+
}
17651+
node["Value"] = scalarExpressionToJSON(normalizedLit)
17652+
} else {
17653+
node["Value"] = scalarExpressionToJSON(o.Value)
17654+
}
17655+
} else {
17656+
node["Value"] = scalarExpressionToJSON(o.Value)
17657+
}
1758517658
}
1758617659
return node
1758717660
case *ast.OrderBulkInsertOption:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"todo": true,
32
"skip_reason": "ScriptDOM normalizes JSON strings in ROWSET_OPTIONS, removing whitespace and changing case"
43
}

0 commit comments

Comments
 (0)