Skip to content

Commit eec8087

Browse files
authored
Merge pull request #23 from goccy/fix-custom-catalog
Fix custom catalog and table
2 parents d1a8ecb + 48f3118 commit eec8087

File tree

15 files changed

+504
-39
lines changed

15 files changed

+504
-39
lines changed

Diff for: catalog_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func (c *myCatalog) FindType(path []string) (types.Type, error) {
5858
return nil, nil
5959
}
6060

61-
func (c *myCatalog) FindConstant(path []string) (types.Constant, error) {
62-
return nil, nil
61+
func (c *myCatalog) FindConstant(path []string) (types.Constant, int, error) {
62+
return nil, 0, nil
6363
}
6464

6565
func (c *myCatalog) FindConversion(from, to types.Type) (types.Conversion, error) {

Diff for: internal/ccall/go-zetasql/bind_darwin.go

+69
Original file line numberDiff line numberDiff line change
@@ -28355,6 +28355,20 @@ func zetasql_Catalog_FindType(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *un
2835528355
C.export_zetasql_Catalog_FindType(arg0, arg1, arg2, arg3)
2835628356
}
2835728357

28358+
func Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *int, arg4 *unsafe.Pointer) {
28359+
zetasql_Catalog_FindConstant(
28360+
arg0,
28361+
arg1,
28362+
arg2,
28363+
(*C.int)(unsafe.Pointer(arg3)),
28364+
arg4,
28365+
)
28366+
}
28367+
28368+
func zetasql_Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *C.int, arg4 *unsafe.Pointer) {
28369+
C.export_zetasql_Catalog_FindConstant(arg0, arg1, arg2, arg3, arg4)
28370+
}
28371+
2835828372
func Catalog_SuggestTable(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer) {
2835928373
zetasql_Catalog_SuggestTable(
2836028374
arg0,
@@ -28899,6 +28913,61 @@ func zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0 unsafe.Pointer, arg1 unsafe.
2889928913
C.export_zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0, arg1)
2890028914
}
2890128915

28916+
func Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28917+
zetasql_Constant_Name(
28918+
arg0,
28919+
arg1,
28920+
)
28921+
}
28922+
28923+
func zetasql_Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28924+
C.export_zetasql_Constant_Name(arg0, arg1)
28925+
}
28926+
28927+
func Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28928+
zetasql_Constant_FullName(
28929+
arg0,
28930+
arg1,
28931+
)
28932+
}
28933+
28934+
func zetasql_Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28935+
C.export_zetasql_Constant_FullName(arg0, arg1)
28936+
}
28937+
28938+
func Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28939+
zetasql_Constant_type(
28940+
arg0,
28941+
arg1,
28942+
)
28943+
}
28944+
28945+
func zetasql_Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28946+
C.export_zetasql_Constant_type(arg0, arg1)
28947+
}
28948+
28949+
func Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28950+
zetasql_Constant_DebugString(
28951+
arg0,
28952+
arg1,
28953+
)
28954+
}
28955+
28956+
func zetasql_Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28957+
C.export_zetasql_Constant_DebugString(arg0, arg1)
28958+
}
28959+
28960+
func Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28961+
zetasql_Constant_name_path(
28962+
arg0,
28963+
arg1,
28964+
)
28965+
}
28966+
28967+
func zetasql_Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28968+
C.export_zetasql_Constant_name_path(arg0, arg1)
28969+
}
28970+
2890228971
func Model_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2890328972
zetasql_Model_Name(
2890428973
arg0,

Diff for: internal/ccall/go-zetasql/bind_linux.go

+69
Original file line numberDiff line numberDiff line change
@@ -28358,6 +28358,20 @@ func zetasql_Catalog_FindType(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *un
2835828358
C.export_zetasql_Catalog_FindType(arg0, arg1, arg2, arg3)
2835928359
}
2836028360

28361+
func Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *int, arg4 *unsafe.Pointer) {
28362+
zetasql_Catalog_FindConstant(
28363+
arg0,
28364+
arg1,
28365+
arg2,
28366+
(*C.int)(unsafe.Pointer(arg3)),
28367+
arg4,
28368+
)
28369+
}
28370+
28371+
func zetasql_Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *C.int, arg4 *unsafe.Pointer) {
28372+
C.export_zetasql_Catalog_FindConstant(arg0, arg1, arg2, arg3, arg4)
28373+
}
28374+
2836128375
func Catalog_SuggestTable(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer) {
2836228376
zetasql_Catalog_SuggestTable(
2836328377
arg0,
@@ -28902,6 +28916,61 @@ func zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0 unsafe.Pointer, arg1 unsafe.
2890228916
C.export_zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0, arg1)
2890328917
}
2890428918

28919+
func Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28920+
zetasql_Constant_Name(
28921+
arg0,
28922+
arg1,
28923+
)
28924+
}
28925+
28926+
func zetasql_Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28927+
C.export_zetasql_Constant_Name(arg0, arg1)
28928+
}
28929+
28930+
func Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28931+
zetasql_Constant_FullName(
28932+
arg0,
28933+
arg1,
28934+
)
28935+
}
28936+
28937+
func zetasql_Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28938+
C.export_zetasql_Constant_FullName(arg0, arg1)
28939+
}
28940+
28941+
func Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28942+
zetasql_Constant_type(
28943+
arg0,
28944+
arg1,
28945+
)
28946+
}
28947+
28948+
func zetasql_Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28949+
C.export_zetasql_Constant_type(arg0, arg1)
28950+
}
28951+
28952+
func Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28953+
zetasql_Constant_DebugString(
28954+
arg0,
28955+
arg1,
28956+
)
28957+
}
28958+
28959+
func zetasql_Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28960+
C.export_zetasql_Constant_DebugString(arg0, arg1)
28961+
}
28962+
28963+
func Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28964+
zetasql_Constant_name_path(
28965+
arg0,
28966+
arg1,
28967+
)
28968+
}
28969+
28970+
func zetasql_Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
28971+
C.export_zetasql_Constant_name_path(arg0, arg1)
28972+
}
28973+
2890528974
func Model_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2890628975
zetasql_Model_Name(
2890728976
arg0,

Diff for: internal/ccall/go-zetasql/callback_darwin.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type GoCatalog struct {
4848
FindTableValuedFunction func([]string) (unsafe.Pointer, error)
4949
FindProcedure func([]string) (unsafe.Pointer, error)
5050
FindType func([]string) (unsafe.Pointer, error)
51-
FindConstant func([]string) (unsafe.Pointer, error)
51+
FindConstant func([]string) (unsafe.Pointer, int, error)
5252
FindConversion func(unsafe.Pointer, unsafe.Pointer) (unsafe.Pointer, error)
5353
ExtendedTypeSuperTypes func(unsafe.Pointer) (unsafe.Pointer, error)
5454
SuggestTable func([]string) string
@@ -202,17 +202,18 @@ func GoCatalog_FindType(v unsafe.Pointer, pathPtr unsafe.Pointer, typ *unsafe.Po
202202
}
203203

204204
//export GoCatalog_FindConstant
205-
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, constant *unsafe.Pointer, ret **C.char) {
205+
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, numNamesConsumed *C.int, constant *unsafe.Pointer, ret **C.char) {
206206
h := *(*cgo.Handle)(v)
207207
cat := h.Value().(*GoCatalog)
208208
var path []string
209209
ptrToSlice(pathPtr, func(p unsafe.Pointer) {
210210
path = append(path, C.GoString((*C.char)(p)))
211211
})
212-
consPtr, err := cat.FindConstant(path)
212+
consPtr, num, err := cat.FindConstant(path)
213213
if err != nil {
214214
*ret = C.CString(err.Error())
215215
} else {
216+
*numNamesConsumed = C.int(num)
216217
*constant = consPtr
217218
}
218219
}
@@ -344,9 +345,9 @@ func GoTable_IsValueTable(v unsafe.Pointer) C.int {
344345
h := *(*cgo.Handle)(v)
345346
table := h.Value().(*GoTable)
346347
if table.IsValueTable() {
347-
return 0
348+
return 1
348349
}
349-
return 1
350+
return 0
350351
}
351352

352353
//export GoTable_SerializationID
@@ -384,9 +385,9 @@ func GoTable_SupportsAnonymization(v unsafe.Pointer) C.int {
384385
h := *(*cgo.Handle)(v)
385386
table := h.Value().(*GoTable)
386387
if table.SupportsAnonymization() {
387-
return 0
388+
return 1
388389
}
389-
return 1
390+
return 0
390391
}
391392

392393
//export GoTable_TableTypeName

Diff for: internal/ccall/go-zetasql/callback_linux.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type GoCatalog struct {
4949
FindTableValuedFunction func([]string) (unsafe.Pointer, error)
5050
FindProcedure func([]string) (unsafe.Pointer, error)
5151
FindType func([]string) (unsafe.Pointer, error)
52-
FindConstant func([]string) (unsafe.Pointer, error)
52+
FindConstant func([]string) (unsafe.Pointer, int, error)
5353
FindConversion func(unsafe.Pointer, unsafe.Pointer) (unsafe.Pointer, error)
5454
ExtendedTypeSuperTypes func(unsafe.Pointer) (unsafe.Pointer, error)
5555
SuggestTable func([]string) string
@@ -203,17 +203,18 @@ func GoCatalog_FindType(v unsafe.Pointer, pathPtr unsafe.Pointer, typ *unsafe.Po
203203
}
204204

205205
//export GoCatalog_FindConstant
206-
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, constant *unsafe.Pointer, ret **C.char) {
206+
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, numNamesConsumed *C.int, constant *unsafe.Pointer, ret **C.char) {
207207
h := *(*cgo.Handle)(v)
208208
cat := h.Value().(*GoCatalog)
209209
var path []string
210210
ptrToSlice(pathPtr, func(p unsafe.Pointer) {
211211
path = append(path, C.GoString((*C.char)(p)))
212212
})
213-
consPtr, err := cat.FindConstant(path)
213+
consPtr, num, err := cat.FindConstant(path)
214214
if err != nil {
215215
*ret = C.CString(err.Error())
216216
} else {
217+
*numNamesConsumed = C.int(num)
217218
*constant = consPtr
218219
}
219220
}
@@ -345,9 +346,9 @@ func GoTable_IsValueTable(v unsafe.Pointer) C.int {
345346
h := *(*cgo.Handle)(v)
346347
table := h.Value().(*GoTable)
347348
if table.IsValueTable() {
348-
return 0
349+
return 1
349350
}
350-
return 1
351+
return 0
351352
}
352353

353354
//export GoTable_SerializationID
@@ -385,9 +386,9 @@ func GoTable_SupportsAnonymization(v unsafe.Pointer) C.int {
385386
h := *(*cgo.Handle)(v)
386387
table := h.Value().(*GoTable)
387388
if table.SupportsAnonymization() {
388-
return 0
389+
return 1
389390
}
390-
return 1
391+
return 0
391392
}
392393

393394
//export GoTable_TableTypeName

Diff for: internal/ccall/go-zetasql/public/catalog/bridge.inc

+22
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,28 @@ public:
194194
}
195195

196196
absl::Status FindConstantWithPathPrefix(const absl::Span<const std::string> path, int* num_names_consumed, const Constant** constant, const FindOptions& options = FindOptions()) {
197+
if (path.empty()) {
198+
return EmptyNamePathInternalError("Constant");
199+
}
200+
GoSlice *path_slice = (GoSlice *)malloc(sizeof(GoSlice));
201+
const char **data = (const char **)malloc(sizeof(void *) * path.size());
202+
for (size_t i = 0; i < path.size(); i++) {
203+
data[i] = path[i].c_str();
204+
}
205+
path_slice->data = (void *)data;
206+
path_slice->len = path.size();
207+
path_slice->cap = path.size();
208+
209+
void *constV = nullptr;
210+
char *ret = nullptr;
211+
GoCatalog_FindConstant(this->go_catalog_ptr, (void *)path_slice, num_names_consumed, &constV, &ret);
212+
if (constV == nullptr) {
213+
return ConstantNotFoundError(path);
214+
}
215+
if (ret != nullptr) {
216+
return absl::InvalidArgumentError(ret);
217+
}
218+
*constant = (const Constant *)constV;
197219
return absl::OkStatus();
198220
}
199221

Diff for: internal/ccall/go-zetasql/public/simple_catalog/bind_darwin.go

+69
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,20 @@ func simple_catalog_Catalog_FindType(arg0 unsafe.Pointer, arg1 unsafe.Pointer, a
22042204
C.export_zetasql_public_simple_catalog_Catalog_FindType(arg0, arg1, arg2, arg3)
22052205
}
22062206

2207+
func Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *int, arg4 *unsafe.Pointer) {
2208+
simple_catalog_Catalog_FindConstant(
2209+
arg0,
2210+
arg1,
2211+
arg2,
2212+
(*C.int)(unsafe.Pointer(arg3)),
2213+
arg4,
2214+
)
2215+
}
2216+
2217+
func simple_catalog_Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *C.int, arg4 *unsafe.Pointer) {
2218+
C.export_zetasql_public_simple_catalog_Catalog_FindConstant(arg0, arg1, arg2, arg3, arg4)
2219+
}
2220+
22072221
func Catalog_SuggestTable(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer) {
22082222
simple_catalog_Catalog_SuggestTable(
22092223
arg0,
@@ -2748,6 +2762,61 @@ func simple_catalog_SimpleCatalog_AddZetaSQLFunctions(arg0 unsafe.Pointer, arg1
27482762
C.export_zetasql_public_simple_catalog_SimpleCatalog_AddZetaSQLFunctions(arg0, arg1)
27492763
}
27502764

2765+
func Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2766+
simple_catalog_Constant_Name(
2767+
arg0,
2768+
arg1,
2769+
)
2770+
}
2771+
2772+
func simple_catalog_Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2773+
C.export_zetasql_public_simple_catalog_Constant_Name(arg0, arg1)
2774+
}
2775+
2776+
func Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2777+
simple_catalog_Constant_FullName(
2778+
arg0,
2779+
arg1,
2780+
)
2781+
}
2782+
2783+
func simple_catalog_Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2784+
C.export_zetasql_public_simple_catalog_Constant_FullName(arg0, arg1)
2785+
}
2786+
2787+
func Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2788+
simple_catalog_Constant_type(
2789+
arg0,
2790+
arg1,
2791+
)
2792+
}
2793+
2794+
func simple_catalog_Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2795+
C.export_zetasql_public_simple_catalog_Constant_type(arg0, arg1)
2796+
}
2797+
2798+
func Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2799+
simple_catalog_Constant_DebugString(
2800+
arg0,
2801+
arg1,
2802+
)
2803+
}
2804+
2805+
func simple_catalog_Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2806+
C.export_zetasql_public_simple_catalog_Constant_DebugString(arg0, arg1)
2807+
}
2808+
2809+
func Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2810+
simple_catalog_Constant_name_path(
2811+
arg0,
2812+
arg1,
2813+
)
2814+
}
2815+
2816+
func simple_catalog_Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
2817+
C.export_zetasql_public_simple_catalog_Constant_name_path(arg0, arg1)
2818+
}
2819+
27512820
func Model_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
27522821
simple_catalog_Model_Name(
27532822
arg0,

0 commit comments

Comments
 (0)