Changeset: be26ae7ea476 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/be26ae7ea476
Added Files:
clients/examples/C/bincopydecimal_impl.h
Modified Files:
clients/examples/C/CMakeLists.txt
clients/examples/C/bincopydata.c
clients/examples/C/bincopydata.h
sql/test/bincopy/Tests/bincopy_support.py
Branch: Jun2023
Log Message:
Ensure decimal testdata does not go out of range
diffs (222 lines):
diff --git a/clients/examples/C/CMakeLists.txt
b/clients/examples/C/CMakeLists.txt
--- a/clients/examples/C/CMakeLists.txt
+++ b/clients/examples/C/CMakeLists.txt
@@ -61,6 +61,7 @@ add_executable(bincopydata
bincopydata.h
bincopytemporaldata.c
bincopyuuid.c
+ bincopydecimal_impl.h
)
target_link_libraries(bincopydata
diff --git a/clients/examples/C/bincopydata.c b/clients/examples/C/bincopydata.c
--- a/clients/examples/C/bincopydata.c
+++ b/clients/examples/C/bincopydata.c
@@ -271,6 +271,44 @@ gen_json(FILE *f, bool byteswap, long nr
}
}
+#define FUNCNAME gen_decimal_tinyints
+#define STYP int8_t
+#define UTYP uint8_t
+#define STYP_MAX (INT8_MAX)
+// #define CONVERT
+#include "bincopydecimal_impl.h"
+
+#define FUNCNAME gen_decimal_smallints
+#define STYP int16_t
+#define UTYP uint16_t
+#define STYP_MAX (INT16_MAX)
+#define CONVERT copy_binary_convert16
+#include "bincopydecimal_impl.h"
+
+#define FUNCNAME gen_decimal_ints
+#define STYP int32_t
+#define UTYP uint32_t
+#define STYP_MAX (INT32_MAX)
+#define CONVERT copy_binary_convert32
+#include "bincopydecimal_impl.h"
+
+
+#define FUNCNAME gen_decimal_bigints
+#define STYP int64_t
+#define UTYP uint64_t
+#define STYP_MAX (INT64_MAX)
+#define CONVERT copy_binary_convert64
+#include "bincopydecimal_impl.h"
+
+#ifdef HAVE_HGE
+ #define FUNCNAME gen_decimal_hugeints
+ #define STYP hge
+ #define UTYP uhge
+ #define STYP_MAX (HGE_MAX)
+ #define CONVERT copy_binary_convert128
+ #include "bincopydecimal_impl.h"
+#endif
+
typedef void (*generator_t)(FILE *f, bool byteswap, long nrecs, char
*argument);
static struct gen {
@@ -291,6 +329,14 @@ static struct gen {
{ "hugeints", gen_hugeints },
#endif
//
+ { "dec_tinyints", gen_decimal_tinyints, .arg_allowed=true },
+ { "dec_smallints", gen_decimal_smallints, .arg_allowed=true },
+ { "dec_ints", gen_decimal_ints, .arg_allowed=true },
+ { "dec_bigints", gen_decimal_bigints, .arg_allowed=true },
+#ifdef HAVE_HGE
+ { "dec_hugeints", gen_decimal_hugeints, .arg_allowed=true },
+#endif
+ //
{ "strings", gen_strings },
{ "large_strings", gen_large_strings },
{ "broken_strings", gen_broken_strings },
@@ -352,7 +398,7 @@ pick_generator(const char *full_name, ch
char *name = strdup(full_name);
*arg = NULL;
- char *sep = strchr(name, ':');
+ char *sep = strchr(name, '!');
if (sep != NULL) {
*arg = strdup(sep + 1);
*sep = '\0';
diff --git a/clients/examples/C/bincopydata.h b/clients/examples/C/bincopydata.h
--- a/clients/examples/C/bincopydata.h
+++ b/clients/examples/C/bincopydata.h
@@ -15,6 +15,13 @@
_Noreturn void croak(int status, const char *msg, ...)
__attribute__((__format__(__printf__, 2, 3)));
+void gen_decimal_tinyints(FILE *f, bool byteswap, long nrecs, char *arg);
+void gen_decimal_smallints(FILE *f, bool byteswap, long nrecs, char *arg);
+void gen_decimal_ints(FILE *f, bool byteswap, long nrecs, char *arg);
+void gen_decimal_bigints(FILE *f, bool byteswap, long nrecs, char *arg);
+#ifdef HAVE_HGE
+void gen_decimal_hugeints(FILE *f, bool byteswap, long nrecs, char *arg);
+#endif
void gen_timestamps(FILE *f, bool byteswap, long nrecs, char *arg);
diff --git a/clients/examples/C/bincopydecimal_impl.h
b/clients/examples/C/bincopydecimal_impl.h
new file mode 100644
--- /dev/null
+++ b/clients/examples/C/bincopydecimal_impl.h
@@ -0,0 +1,53 @@
+/*
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * 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 - 2023 MonetDB B.V.
+ */
+
+
+void
+FUNCNAME(FILE *f, bool byteswap, long nrecs, char *arg)
+{
+ if (!arg)
+ croak(2, "this generator needs a scale argument");
+
+ char *end = NULL;
+ int scale = (int)strtol(arg, &end, 10);
+ if (*arg == '\0' || *end != '\0')
+ croak(2, "invalid scale argument");
+ STYP hi = 1;
+ while (scale-- > 0)
+ hi *= 10;
+ hi -= 1;
+ assert(hi < STYP_MAX / 2);
+
+ STYP n = 0;
+ for (long i = 0; i < nrecs; i++) {
+ STYP svalue = n / 2;
+ if (i % 2 != 0)
+ svalue = -svalue;
+ UTYP uvalue = (UTYP) svalue;
+#ifdef CONVERT
+ if (byteswap)
+ CONVERT(&uvalue);
+#else
+ (void)byteswap;
+#endif
+ fwrite(&uvalue, sizeof(uvalue), 1, f);
+
+ if (n == 2 * hi + 1)
+ n = 0;
+ else
+ n++;
+ }
+}
+
+#undef FUNCNAME
+#undef STYP
+#undef UTYP
+#undef STYP_MAX
+#undef CONVERT
diff --git a/sql/test/bincopy/Tests/bincopy_support.py
b/sql/test/bincopy/Tests/bincopy_support.py
--- a/sql/test/bincopy/Tests/bincopy_support.py
+++ b/sql/test/bincopy/Tests/bincopy_support.py
@@ -95,7 +95,7 @@ def run_test(side, testcase):
data_maker.additionally('ON', 'ON ' + side.upper())
data_maker.additionally('NRECS', NRECS)
data_maker.additionally('NRECS_DIV_4', NRECS / 4)
- massage = lambda s: re.sub(r'@(>?\w+)@', data_maker.substitute_match, s)
+ massage = lambda s: re.sub(r'@(>?(\w|!)+)@', data_maker.substitute_match,
s)
code = massage(code)
code = f"START TRANSACTION;\n{code}\nROLLBACK;\n"
open(os.path.join(BINCOPY_FILES, 'test.sql'), "w").write(code)
@@ -444,13 +444,21 @@ CREATE TABLE foo(
COPY BINARY INTO foo FROM
-- bte: i1, d1_1, d2_1
- @tinyints@, @tinyints@, @tinyints@,
+ @dec_tinyints!1@,
+ @dec_tinyints!1@,
+ @dec_tinyints!1@,
-- sht: i2, d3_2, d4_2
- @smallints@, @smallints@, @smallints@,
+ @dec_smallints!3@,
+ @dec_smallints!3@,
+ @dec_smallints!3@,
-- int: i4, d5_2, d9_2
- @ints@, @ints@, @ints@,
+ @dec_ints!5@,
+ @dec_ints!5@,
+ @dec_ints!5@,
-- lng: i8, d10_2, d18_2
- @bigints@, @bigints@, @bigints@
+ @dec_bigints!10@,
+ @dec_bigints!10@,
+ @dec_bigints!10@
@ON@;
COPY
@@ -458,13 +466,21 @@ SELECT i1, d1_1, d2_1, i2, d3_2, d4_2, i
FROM foo
INTO BINARY
-- bte: i1, d1_1, d2_1
- @>tinyints@, @>tinyints@, @>tinyints@,
+ @>dec_tinyints!1@,
+ @>dec_tinyints!1@,
+ @>dec_tinyints!1@,
-- sht: i2, d3_2, d4_2
- @>smallints@, @>smallints@, @>smallints@,
+ @>dec_smallints!3@,
+ @>dec_smallints!3@,
+ @>dec_smallints!3@,
-- int: i4, d5_2, d9_2
- @>ints@, @>ints@, @>ints@,
+ @>dec_ints!5@,
+ @>dec_ints!5@,
+ @>dec_ints!5@,
-- lng: i8, d10_2, d18_2
- @>bigints@, @>bigints@, @>bigints@
+ @>dec_bigints!10@,
+ @>dec_bigints!10@,
+ @>dec_bigints!10@
@ON@;
WITH verified AS (
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]