Skip to content

Commit

Permalink
Fix custom catalog and table
Browse files Browse the repository at this point in the history
goccy committed Nov 22, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d1a8ecb commit 48f3118
Showing 15 changed files with 504 additions and 39 deletions.
4 changes: 2 additions & 2 deletions catalog_test.go
Original file line number Diff line number Diff line change
@@ -58,8 +58,8 @@ func (c *myCatalog) FindType(path []string) (types.Type, error) {
return nil, nil
}

func (c *myCatalog) FindConstant(path []string) (types.Constant, error) {
return nil, nil
func (c *myCatalog) FindConstant(path []string) (types.Constant, int, error) {
return nil, 0, nil
}

func (c *myCatalog) FindConversion(from, to types.Type) (types.Conversion, error) {
69 changes: 69 additions & 0 deletions internal/ccall/go-zetasql/bind_darwin.go
Original file line number Diff line number Diff line change
@@ -28355,6 +28355,20 @@ func zetasql_Catalog_FindType(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *un
C.export_zetasql_Catalog_FindType(arg0, arg1, arg2, arg3)
}

func Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *int, arg4 *unsafe.Pointer) {
zetasql_Catalog_FindConstant(
arg0,
arg1,
arg2,
(*C.int)(unsafe.Pointer(arg3)),
arg4,
)
}

func zetasql_Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *C.int, arg4 *unsafe.Pointer) {
C.export_zetasql_Catalog_FindConstant(arg0, arg1, arg2, arg3, arg4)
}

func Catalog_SuggestTable(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer) {
zetasql_Catalog_SuggestTable(
arg0,
@@ -28899,6 +28913,61 @@ func zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0 unsafe.Pointer, arg1 unsafe.
C.export_zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0, arg1)
}

func Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_Name(
arg0,
arg1,
)
}

func zetasql_Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_Name(arg0, arg1)
}

func Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_FullName(
arg0,
arg1,
)
}

func zetasql_Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_FullName(arg0, arg1)
}

func Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_type(
arg0,
arg1,
)
}

func zetasql_Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_type(arg0, arg1)
}

func Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_DebugString(
arg0,
arg1,
)
}

func zetasql_Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_DebugString(arg0, arg1)
}

func Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_name_path(
arg0,
arg1,
)
}

func zetasql_Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_name_path(arg0, arg1)
}

func Model_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Model_Name(
arg0,
69 changes: 69 additions & 0 deletions internal/ccall/go-zetasql/bind_linux.go
Original file line number Diff line number Diff line change
@@ -28358,6 +28358,20 @@ func zetasql_Catalog_FindType(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *un
C.export_zetasql_Catalog_FindType(arg0, arg1, arg2, arg3)
}

func Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *int, arg4 *unsafe.Pointer) {
zetasql_Catalog_FindConstant(
arg0,
arg1,
arg2,
(*C.int)(unsafe.Pointer(arg3)),
arg4,
)
}

func zetasql_Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *C.int, arg4 *unsafe.Pointer) {
C.export_zetasql_Catalog_FindConstant(arg0, arg1, arg2, arg3, arg4)
}

func Catalog_SuggestTable(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer) {
zetasql_Catalog_SuggestTable(
arg0,
@@ -28902,6 +28916,61 @@ func zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0 unsafe.Pointer, arg1 unsafe.
C.export_zetasql_SimpleCatalog_AddZetaSQLFunctions(arg0, arg1)
}

func Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_Name(
arg0,
arg1,
)
}

func zetasql_Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_Name(arg0, arg1)
}

func Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_FullName(
arg0,
arg1,
)
}

func zetasql_Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_FullName(arg0, arg1)
}

func Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_type(
arg0,
arg1,
)
}

func zetasql_Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_type(arg0, arg1)
}

func Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_DebugString(
arg0,
arg1,
)
}

func zetasql_Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_DebugString(arg0, arg1)
}

func Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Constant_name_path(
arg0,
arg1,
)
}

func zetasql_Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Constant_name_path(arg0, arg1)
}

func Model_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
zetasql_Model_Name(
arg0,
15 changes: 8 additions & 7 deletions internal/ccall/go-zetasql/callback_darwin.go
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ type GoCatalog struct {
FindTableValuedFunction func([]string) (unsafe.Pointer, error)
FindProcedure func([]string) (unsafe.Pointer, error)
FindType func([]string) (unsafe.Pointer, error)
FindConstant func([]string) (unsafe.Pointer, error)
FindConstant func([]string) (unsafe.Pointer, int, error)
FindConversion func(unsafe.Pointer, unsafe.Pointer) (unsafe.Pointer, error)
ExtendedTypeSuperTypes func(unsafe.Pointer) (unsafe.Pointer, error)
SuggestTable func([]string) string
@@ -202,17 +202,18 @@ func GoCatalog_FindType(v unsafe.Pointer, pathPtr unsafe.Pointer, typ *unsafe.Po
}

//export GoCatalog_FindConstant
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, constant *unsafe.Pointer, ret **C.char) {
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, numNamesConsumed *C.int, constant *unsafe.Pointer, ret **C.char) {
h := *(*cgo.Handle)(v)
cat := h.Value().(*GoCatalog)
var path []string
ptrToSlice(pathPtr, func(p unsafe.Pointer) {
path = append(path, C.GoString((*C.char)(p)))
})
consPtr, err := cat.FindConstant(path)
consPtr, num, err := cat.FindConstant(path)
if err != nil {
*ret = C.CString(err.Error())
} else {
*numNamesConsumed = C.int(num)
*constant = consPtr
}
}
@@ -344,9 +345,9 @@ func GoTable_IsValueTable(v unsafe.Pointer) C.int {
h := *(*cgo.Handle)(v)
table := h.Value().(*GoTable)
if table.IsValueTable() {
return 0
return 1
}
return 1
return 0
}

//export GoTable_SerializationID
@@ -384,9 +385,9 @@ func GoTable_SupportsAnonymization(v unsafe.Pointer) C.int {
h := *(*cgo.Handle)(v)
table := h.Value().(*GoTable)
if table.SupportsAnonymization() {
return 0
return 1
}
return 1
return 0
}

//export GoTable_TableTypeName
15 changes: 8 additions & 7 deletions internal/ccall/go-zetasql/callback_linux.go
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ type GoCatalog struct {
FindTableValuedFunction func([]string) (unsafe.Pointer, error)
FindProcedure func([]string) (unsafe.Pointer, error)
FindType func([]string) (unsafe.Pointer, error)
FindConstant func([]string) (unsafe.Pointer, error)
FindConstant func([]string) (unsafe.Pointer, int, error)
FindConversion func(unsafe.Pointer, unsafe.Pointer) (unsafe.Pointer, error)
ExtendedTypeSuperTypes func(unsafe.Pointer) (unsafe.Pointer, error)
SuggestTable func([]string) string
@@ -203,17 +203,18 @@ func GoCatalog_FindType(v unsafe.Pointer, pathPtr unsafe.Pointer, typ *unsafe.Po
}

//export GoCatalog_FindConstant
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, constant *unsafe.Pointer, ret **C.char) {
func GoCatalog_FindConstant(v unsafe.Pointer, pathPtr unsafe.Pointer, numNamesConsumed *C.int, constant *unsafe.Pointer, ret **C.char) {
h := *(*cgo.Handle)(v)
cat := h.Value().(*GoCatalog)
var path []string
ptrToSlice(pathPtr, func(p unsafe.Pointer) {
path = append(path, C.GoString((*C.char)(p)))
})
consPtr, err := cat.FindConstant(path)
consPtr, num, err := cat.FindConstant(path)
if err != nil {
*ret = C.CString(err.Error())
} else {
*numNamesConsumed = C.int(num)
*constant = consPtr
}
}
@@ -345,9 +346,9 @@ func GoTable_IsValueTable(v unsafe.Pointer) C.int {
h := *(*cgo.Handle)(v)
table := h.Value().(*GoTable)
if table.IsValueTable() {
return 0
return 1
}
return 1
return 0
}

//export GoTable_SerializationID
@@ -385,9 +386,9 @@ func GoTable_SupportsAnonymization(v unsafe.Pointer) C.int {
h := *(*cgo.Handle)(v)
table := h.Value().(*GoTable)
if table.SupportsAnonymization() {
return 0
return 1
}
return 1
return 0
}

//export GoTable_TableTypeName
22 changes: 22 additions & 0 deletions internal/ccall/go-zetasql/public/catalog/bridge.inc
Original file line number Diff line number Diff line change
@@ -194,6 +194,28 @@ public:
}

absl::Status FindConstantWithPathPrefix(const absl::Span<const std::string> path, int* num_names_consumed, const Constant** constant, const FindOptions& options = FindOptions()) {
if (path.empty()) {
return EmptyNamePathInternalError("Constant");
}
GoSlice *path_slice = (GoSlice *)malloc(sizeof(GoSlice));
const char **data = (const char **)malloc(sizeof(void *) * path.size());
for (size_t i = 0; i < path.size(); i++) {
data[i] = path[i].c_str();
}
path_slice->data = (void *)data;
path_slice->len = path.size();
path_slice->cap = path.size();

void *constV = nullptr;
char *ret = nullptr;
GoCatalog_FindConstant(this->go_catalog_ptr, (void *)path_slice, num_names_consumed, &constV, &ret);
if (constV == nullptr) {
return ConstantNotFoundError(path);
}
if (ret != nullptr) {
return absl::InvalidArgumentError(ret);
}
*constant = (const Constant *)constV;
return absl::OkStatus();
}

69 changes: 69 additions & 0 deletions internal/ccall/go-zetasql/public/simple_catalog/bind_darwin.go
Original file line number Diff line number Diff line change
@@ -2204,6 +2204,20 @@ func simple_catalog_Catalog_FindType(arg0 unsafe.Pointer, arg1 unsafe.Pointer, a
C.export_zetasql_public_simple_catalog_Catalog_FindType(arg0, arg1, arg2, arg3)
}

func Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *int, arg4 *unsafe.Pointer) {
simple_catalog_Catalog_FindConstant(
arg0,
arg1,
arg2,
(*C.int)(unsafe.Pointer(arg3)),
arg4,
)
}

func simple_catalog_Catalog_FindConstant(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer, arg3 *C.int, arg4 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Catalog_FindConstant(arg0, arg1, arg2, arg3, arg4)
}

func Catalog_SuggestTable(arg0 unsafe.Pointer, arg1 unsafe.Pointer, arg2 *unsafe.Pointer) {
simple_catalog_Catalog_SuggestTable(
arg0,
@@ -2748,6 +2762,61 @@ func simple_catalog_SimpleCatalog_AddZetaSQLFunctions(arg0 unsafe.Pointer, arg1
C.export_zetasql_public_simple_catalog_SimpleCatalog_AddZetaSQLFunctions(arg0, arg1)
}

func Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
simple_catalog_Constant_Name(
arg0,
arg1,
)
}

func simple_catalog_Constant_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Constant_Name(arg0, arg1)
}

func Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
simple_catalog_Constant_FullName(
arg0,
arg1,
)
}

func simple_catalog_Constant_FullName(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Constant_FullName(arg0, arg1)
}

func Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
simple_catalog_Constant_type(
arg0,
arg1,
)
}

func simple_catalog_Constant_type(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Constant_type(arg0, arg1)
}

func Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
simple_catalog_Constant_DebugString(
arg0,
arg1,
)
}

func simple_catalog_Constant_DebugString(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Constant_DebugString(arg0, arg1)
}

func Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
simple_catalog_Constant_name_path(
arg0,
arg1,
)
}

func simple_catalog_Constant_name_path(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Constant_name_path(arg0, arg1)
}

func Model_Name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
simple_catalog_Model_Name(
arg0,
Loading

0 comments on commit 48f3118

Please sign in to comment.