Changeset: 1d88b467a03c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1d88b467a03c Modified Files: monetdb5/modules/mal/pcre.c monetdb5/modules/mal/pcre_pub.h monetdb5/modules/weldudfs/weld_udfs.c sql/backends/monet5/rel_weld.c Branch: rel-weld Log Message:
weld: less generic handling for like, but we don't need locks anymore diffs (118 lines): diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c --- a/monetdb5/modules/mal/pcre.c +++ b/monetdb5/modules/mal/pcre.c @@ -163,7 +163,7 @@ re_match_no_ignore(const char *s, RE *pa return 1; } -static void +void re_destroy(RE *p) { while (p) { diff --git a/monetdb5/modules/mal/pcre_pub.h b/monetdb5/modules/mal/pcre_pub.h --- a/monetdb5/modules/mal/pcre_pub.h +++ b/monetdb5/modules/mal/pcre_pub.h @@ -18,3 +18,4 @@ typedef struct RE { int re_simple(const char *pat); RE *re_create(const char *pat, int nr); int re_match_no_ignore(const char *s, RE *pattern); +void re_destroy(RE *p); diff --git a/monetdb5/modules/weldudfs/weld_udfs.c b/monetdb5/modules/weldudfs/weld_udfs.c --- a/monetdb5/modules/weldudfs/weld_udfs.c +++ b/monetdb5/modules/weldudfs/weld_udfs.c @@ -17,35 +17,29 @@ typedef struct { int64_t len; } i8vec; -MT_Lock initLock MT_LOCK_INITIALIZER("udfs_init"); - -mal_export void state_init(i8vec *op, int64_t *state_ptr); -mal_export void like(int64_t *state_ptr, i8vec *col, i8vec *pattern, i8vec *exc, int8_t *result); +mal_export void like_pattern_init(i8vec *pattern, i8vec *exc, int64_t *state_ptr); +mal_export void like(int64_t *state_ptr, i8vec *col, int8_t *result); +mal_export void like_pattern_cleanup(int64_t *state_ptr, int64_t *); mal_export void year(int32_t *col, int32_t *result); -void state_init(i8vec *op, int64_t *state_ptr) { - (void)op; - void *ptr = calloc(0, sizeof(void*)); - *state_ptr = (int64_t)ptr; +void like_pattern_init(i8vec *pattern, i8vec *exc, int64_t *state_ptr) { + (void)exc; + int nr = re_simple(pattern->data); + RE *re = re_create(pattern->data, nr); + *state_ptr = (int64_t)re; } -void like(int64_t *state_ptr, i8vec *col, i8vec *pattern, i8vec *exc, int8_t *result) { - (void)exc; - int64_t *adr = (void*)*state_ptr; - RE *re = (RE*)(*adr); - if (re == NULL) { - MT_lock_set(&initLock); - if (re == NULL) { - /* Create a RE struct and save it in the given mem location */ - int nr = re_simple(pattern->data); - re = re_create(pattern->data, nr); - *adr = (int64_t)re; - } - MT_lock_unset(&initLock); - } +void like(int64_t *state_ptr, i8vec *col, int8_t *result) { + RE *re = (RE*)(*state_ptr); *result = (int8_t)re_match_no_ignore(col->data, re); } +void like_pattern_cleanup(int64_t *state_ptr, int64_t *result) { + RE *re = (RE*)(*state_ptr); + re_destroy(re); + *result = 0; +} + void year(int32_t *col, int32_t *result) { (void)MTIMEdate_extract_year(result, col); } diff --git a/sql/backends/monet5/rel_weld.c b/sql/backends/monet5/rel_weld.c --- a/sql/backends/monet5/rel_weld.c +++ b/sql/backends/monet5/rel_weld.c @@ -278,18 +278,28 @@ exp_to_weld(backend *be, weld_state *wst exps_to_weld(be, wstate, exp->r, ""); wprintf(wstate, ")"); } else if (get_cmp(exp) == cmp_filter) { - /* Must be an udf */ str udf = get_weld_func(exp->f); - int state_ptr = wstate->next_var++; - sprintf(wstate->global_init + strlen(wstate->global_init), - "let v%d = cudf[state_init, i64](\"%s\");", state_ptr, udf); - sprintf(wstate->global_cleanup + strlen(wstate->global_cleanup), - "let v%d = cudf[state_cleanup, i64](\"%s\", v%d);", state_ptr, udf, state_ptr); - wprintf(wstate, "cudf[%s, bool](v%d,", udf, state_ptr); - exps_to_weld(be, wstate, exp->l, ", "); - wprintf(wstate, ", "); - exps_to_weld(be, wstate, exp->r, ", "); - wprintf(wstate, ")"); + if (strcmp(udf, "like") == 0) { + int state_ptr = wstate->next_var++; + sprintf(wstate->global_init + strlen(wstate->global_init), + "let v%d = cudf[like_pattern_init, i64](", state_ptr); + /* Process the pattern and the escape */ + unsigned long old_len = wstate->program_len; + exps_to_weld(be, wstate, exp->r, ", "); + /* Add the pattern and the escape to the init udf */ + sprintf(wstate->global_init + strlen(wstate->global_init), "%s);", + wstate->program + old_len); + sprintf(wstate->global_cleanup + strlen(wstate->global_cleanup), + "let v%d = cudf[like_pattern_cleanup, i64](v%d);", state_ptr, state_ptr); + wstate->program_len = old_len; + + wprintf(wstate, "cudf[%s, bool](v%d,", udf, state_ptr); + exps_to_weld(be, wstate, exp->l, ", "); + wprintf(wstate, ")"); + } else { + wstate->error = 1; + return; + } } else if (exp->f) { if (get_weld_cmp(swap_compare(range2lcompare(exp->flag))) == NULL) { wstate->error = 1; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list