Skip to content

Commit a37696d

Browse files
committed
Add JSON support to UDF parameter and return types
1 parent f10eef4 commit a37696d

File tree

15 files changed

+716
-156
lines changed

15 files changed

+716
-156
lines changed

AC_PLAN.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!-- AutoClaude Planning Metadata
2+
Complexity: medium
3+
Branch: auto-generated
4+
Files: 0 files to modify/create
5+
Dependencies: 0 new dependencies
6+
-->
7+
8+
# Implementation Plan - COMPLETED ✅
9+
10+
All requirements from the specification have been successfully implemented:
11+
12+
## Completed Tasks
13+
14+
- [x] **JSON Type Support**: Added Dict[str, Any] support for scalar parameters and List[Dict[str, Any]] for vector parameters
15+
- [x] **Type Aliases**: Created JSON and JsonArray type aliases in functions/typing module following existing patterns
16+
- [x] **SQL Mappings**: Updated sql_type_map and sql_to_type_map to properly map JSON types to SingleStore JSON columns
17+
- [x] **Function Signatures**: Enhanced signature processing to correctly handle JSON types in both parameters and return values
18+
- [x] **Type Validation**: Added proper validation to ensure only Dict[str, Any] is accepted as JSON type
19+
- [x] **Testing**: Verified all JSON variations work correctly (scalar, vector, optional, and type aliases)
20+
- [x] **Code Quality**: Fixed all linting issues and ensured pre-commit checks pass
21+
22+
## Files Modified
23+
24+
1. **singlestoredb/functions/signature.py**: Added JSON type mappings, validation, and normalization
25+
2. **singlestoredb/functions/typing/__init__.py**: Added JSON and JsonArray type aliases
26+
27+
## Key Features Implemented
28+
29+
- ✅ Scalar JSON parameters: `def my_func(data: Dict[str, Any]) -> Dict[str, Any]`
30+
- ✅ Vector JSON parameters: `def my_func(data: List[Dict[str, Any]]) -> List[Dict[str, Any]]`
31+
- ✅ Optional JSON parameters: `def my_func(data: Optional[Dict[str, Any]]) -> str`
32+
- ✅ Type aliases: `def my_func(data: JSON) -> JSON`
33+
- ✅ Vector type aliases: `def my_func(data: JsonArray) -> JsonArray`
34+
- ✅ Proper SQL generation: `JSON NOT NULL`, `JSON NULL`
35+
- ✅ CREATE EXTERNAL FUNCTION integration

AC_PROMPT.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# AutoClaude Implementation Session
2+
3+
You are now in an AutoClaude implementation session. Your task is to implement the specification according to the AC_PLAN.md plan.
4+
5+
## Specification Details
6+
**Title:** Summary
7+
**Project:** singlestoredb-python
8+
**Branch:** udf-json
9+
10+
## Your Task
11+
You are running in the project directory with all necessary context. Please:
12+
13+
1. **Review @AC_SPEC.md** - This contains the original specification
14+
2. **Review @AC_PLAN.md** - This contains your implementation plan
15+
3. **Implement each task** systematically, checking off items as you complete them
16+
4. **Test your implementation** where appropriate
17+
5. **Update AC_PLAN.md** - Mark completed items with [x] instead of [ ]
18+
6. **Create a commit when finished** - See commit instructions below
19+
20+
## Guidelines
21+
- Work incrementally, implementing one feature at a time
22+
- Test frequently to ensure everything works
23+
- Follow the existing code style and patterns
24+
- Create new files only when necessary
25+
- Update existing files when appropriate
26+
- Run any tests that exist in the project
27+
28+
## Commit Instructions
29+
**IMPORTANT:** When you have completed the implementation and all tests are passing:
30+
31+
1. Stage all your changes: `git add .`
32+
2. Create a commit using this message format:
33+
```
34+
{spec_type}: {spec_title}
35+
36+
{spec_summary}
37+
```
38+
39+
Replace:
40+
- `{spec_type}` with "feature"
41+
- `{spec_title}` with "Summary"
42+
- `{spec_summary}` with a brief summary of what was implemented
43+
44+
Example commit command:
45+
```
46+
git commit -m "feature: Summary
47+
48+
[Brief summary of implementation]"
49+
```
50+
51+
## Session Information
52+
- **Working Directory:** /home/ksmith/src/singlestoredb-python/trees/udf-json
53+
- **Branch:** udf-json
54+
55+
Start by running `ls -la` to see the current project structure, then begin implementing according to @AC_PLAN.md.

AC_SPEC.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Summary
2+
3+
We need to support the JSON data type in the UDF application. This means that functions decorated with the @udf decorator need to have a type that corresponds to the JSON type in singlestoredb.
4+
5+
For scalar-valued parameters in UDFs, we will use the Dict[str, Any] type. For vector-valued params, we have to use a generic object type, but in the @udf decorator we can support a Dict[str, Any] override. We can also add type aliases like for other vector types (functions/typing).
6+
7+
Make sure that the SQL type mappings in CREATE EXTERNAL FUNCTION map to JSON.
8+
9+
Make sure that Function signatures in the show/create-function have the JSON type.
10+
11+
## Code locations
12+
• singlestoredb/functions/
13+
14+
---
15+
16+
## Visual Description
17+
18+
This appears to be a handwritten specification or development note on white paper with black ink. The document is structured with a bullet-pointed summary section followed by implementation notes and a code locations section. The handwriting is clear and legible, written in a casual style typical of technical notes or planning documents.
19+
20+
The content focuses on implementing JSON data type support in UDF (User Defined Functions) applications, specifically for SingleStoreDB, with technical details about type mappings and decorator usage.

singlestoredb/functions/decorator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from . import utils
1212
from .dtypes import SQLString
13+
from .typing import JSON
14+
from .typing import JSONArray
1315

1416

1517
ParameterType = Union[
@@ -73,6 +75,8 @@ def expand_types(args: Any) -> Optional[List[Any]]:
7375
for arg in args:
7476
if isinstance(arg, str):
7577
new_args.append(arg)
78+
elif arg in [JSON, JSONArray]:
79+
new_args.append(arg)
7680
elif is_sqlstr_callable(arg):
7781
new_args.append(arg())
7882
elif type(arg) is type:

singlestoredb/functions/dtypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def bytestr(x: Any) -> Optional[bytes]:
117117
-9: converters[9],
118118
15: utf8str,
119119
-15: bytestr,
120+
245: utf8str,
120121
249: utf8str,
121122
-249: bytestr,
122123
250: utf8str,

0 commit comments

Comments
 (0)