Changeset: 1672b72c2ae4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1672b72c2ae4
Added Files:
sql/backends/monet5/copy.h
sql/backends/monet5/copy_convert.c
Modified Files:
sql/backends/monet5/CMakeLists.txt
sql/backends/monet5/copy.c
Branch: copyparpipe
Log Message:
Extract COPYparse_generic to its own separate source file
diffs (229 lines):
diff --git a/sql/backends/monet5/CMakeLists.txt
b/sql/backends/monet5/CMakeLists.txt
--- a/sql/backends/monet5/CMakeLists.txt
+++ b/sql/backends/monet5/CMakeLists.txt
@@ -157,7 +157,8 @@ target_sources(sql
opt_backend.h
for.c for.h
dict.c dict.h
- copy.c
+ copy.c copy.h
+ copy_convert.c
${MONETDB_CURRENT_SQL_SOURCES}
PUBLIC
${sql_public_headers})
diff --git a/sql/backends/monet5/copy.c b/sql/backends/monet5/copy.c
--- a/sql/backends/monet5/copy.c
+++ b/sql/backends/monet5/copy.c
@@ -7,28 +7,16 @@
*/
#include "monetdb_config.h"
-#include "gdk.h"
#include "streams.h"
#include "mel.h"
-#include "mal.h"
-#include "mal_errors.h"
-#include "mal_client.h"
-// #include "mal_instruction.h"
#include "mal_exception.h"
#include "mal_interpreter.h"
+#include "copy.h"
#include "rel_copy.h"
// #define BLOCK_DEBUG 1
-#define MAX_LINE_LENGTH (32 * 1024 * 1024)
-
-#define bailout(f, ...) do { \
- msg = createException(SQL, f, __VA_ARGS__); \
- goto end; \
- } while (0)
-
-
static void
dump_char(int c)
{
@@ -785,69 +773,6 @@ end:
}
static str
-COPYparse_generic(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
-{
- (void)cntxt;
- str msg = MAL_SUCCEED;
- BAT *ret = NULL;
- BAT *block = BATdescriptor(*getArgReference_bat(stk, pci, 1));
- BAT *indices = BATdescriptor(*getArgReference_bat(stk, pci, 2));
- int tpe = getArgGDKType(mb, pci, 3);
- int n;
- void *buffer;
- size_t buffer_len;
- const void *nil_ptr;
- size_t nil_len;
-
- if (block == NULL || indices == NULL)
- bailout("copy.parse_generic", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
- n = BATcount(indices);
-
- ret = COLnew(0, tpe, n, TRANSIENT);
- if (!ret)
- bailout("copy.parse_generic", SQLSTATE(HY013) MAL_MALLOC_FAIL);
-
- nil_ptr = ATOMnilptr(tpe);
- nil_len = ATOMlen(tpe, ATOMnilptr(tpe));
-
- buffer = NULL;
- buffer_len = 0;
- for (int i = 0; i < n; i++) {
- int offset = *(int*)Tloc(indices, i);
- const char *src = Tloc(block, offset);
- const void *p;
- ssize_t len;
- if (is_int_nil(offset)) {
- p = nil_ptr;
- len = nil_len;
- } else {
- len = BATatoms[tpe].atomFromStr(src, &buffer_len,
&buffer, false);
- p = buffer;
- if (len < 0)
- bailout("copy.parse_generic",
SQLSTATE(42000)"Conversion failed for value '%s'", src);
- }
- if (bunfastapp(ret, p) != GDK_SUCCEED)
- bailout("copy.parse_generic", GDK_EXCEPTION);
- }
- BATsetcount(ret, n);
-end:
- GDKfree(buffer);
- if (ret) {
- if (msg == MAL_SUCCEED) {
- *getArgReference_bat(stk, pci, 0) = ret->batCacheid;
- BBPkeepref(ret->batCacheid);
- }
- else
- BBPunfix(ret->batCacheid);
- }
- if (block)
- BBPunfix(block->batCacheid);
- if (indices)
- BBPunfix(indices->batCacheid);
- return msg;
-}
-
-static str
COPYpair_assign(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
(void)cntxt;
diff --git a/sql/backends/monet5/copy.h b/sql/backends/monet5/copy.h
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/copy.h
@@ -0,0 +1,23 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
+ */
+
+#ifndef _COPY_H_
+#define _COPY_H_
+
+
+#define MAX_LINE_LENGTH (32 * 1024 * 1024)
+
+#define bailout(f, ...) do { \
+ msg = createException(SQL, f, __VA_ARGS__); \
+ goto end; \
+ } while (0)
+
+extern str COPYparse_generic(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
+
+
+#endif /*_COPY_H_*/
diff --git a/sql/backends/monet5/copy_convert.c
b/sql/backends/monet5/copy_convert.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/copy_convert.c
@@ -0,0 +1,80 @@
+
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
+ */
+
+#include "monetdb_config.h"
+#include "gdk.h"
+#include "mal.h"
+#include "mal_exception.h"
+#include "mal_interpreter.h"
+
+#include "copy.h"
+
+
+str
+COPYparse_generic(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+{
+ (void)cntxt;
+ str msg = MAL_SUCCEED;
+ BAT *ret = NULL;
+ BAT *block = BATdescriptor(*getArgReference_bat(stk, pci, 1));
+ BAT *indices = BATdescriptor(*getArgReference_bat(stk, pci, 2));
+ int tpe = getArgGDKType(mb, pci, 3);
+ int n;
+ void *buffer;
+ size_t buffer_len;
+ const void *nil_ptr;
+ size_t nil_len;
+
+ if (block == NULL || indices == NULL)
+ bailout("copy.parse_generic", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
+ n = BATcount(indices);
+
+ ret = COLnew(0, tpe, n, TRANSIENT);
+ if (!ret)
+ bailout("copy.parse_generic", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+
+ nil_ptr = ATOMnilptr(tpe);
+ nil_len = ATOMlen(tpe, ATOMnilptr(tpe));
+
+ buffer = NULL;
+ buffer_len = 0;
+ for (int i = 0; i < n; i++) {
+ int offset = *(int*)Tloc(indices, i);
+ const char *src = Tloc(block, offset);
+ const void *p;
+ ssize_t len;
+ if (is_int_nil(offset)) {
+ p = nil_ptr;
+ len = nil_len;
+ } else {
+ len = BATatoms[tpe].atomFromStr(src, &buffer_len,
&buffer, false);
+ p = buffer;
+ if (len < 0)
+ bailout("copy.parse_generic",
SQLSTATE(42000)"Conversion failed for value '%s'", src);
+ }
+ if (bunfastapp(ret, p) != GDK_SUCCEED)
+ bailout("copy.parse_generic", GDK_EXCEPTION);
+ }
+ BATsetcount(ret, n);
+end:
+ GDKfree(buffer);
+ if (ret) {
+ if (msg == MAL_SUCCEED) {
+ *getArgReference_bat(stk, pci, 0) = ret->batCacheid;
+ BBPkeepref(ret->batCacheid);
+ }
+ else
+ BBPunfix(ret->batCacheid);
+ }
+ if (block)
+ BBPunfix(block->batCacheid);
+ if (indices)
+ BBPunfix(indices->batCacheid);
+ return msg;
+}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]