index 5cb1f7f7538564398fbf731c2aaecd9e1315e90d..6a50736be23752fe6ea96c2beaccda8815ea9c8d 100644 (file)
--- a/src/frontend/analyzer.c
+++ b/src/frontend/analyzer.c
SDB_STORE_TYPE_TO_NAME(context));
} /* iter_error */
+static void
+iter_array_error(sdb_strbuf_t *errbuf, int op,
+ int array_type, int cmp, int value_type)
+{
+ sdb_strbuf_sprintf(errbuf, "Invalid array iterator %s %s %s %s",
+ MATCHER_SYM(op), SDB_TYPE_TO_STRING(array_type),
+ MATCHER_SYM(cmp), SDB_TYPE_TO_STRING(value_type));
+ if ((array_type & 0xff) != value_type)
+ sdb_strbuf_append(errbuf, " (type mismatch)");
+ else
+ sdb_strbuf_append(errbuf, " (invalid operator)");
+} /* iter_array_error */
+
static void
cmp_error(sdb_strbuf_t *errbuf, int op, int left, int right)
{
sdb_strbuf_sprintf(errbuf, "Invalid operator %s for types %s and %s",
MATCHER_SYM(op), SDB_TYPE_TO_STRING(left),
SDB_TYPE_TO_STRING(right));
-} /* iter_error */
+} /* cmp_error */
static int
analyze_matcher(int context, sdb_store_matcher_t *m, sdb_strbuf_t *errbuf)
}
if ((ITER_M(m)->type != SDB_SERVICE)
&& (ITER_M(m)->type != SDB_METRIC)
- && (ITER_M(m)->type != SDB_ATTRIBUTE)) {
+ && (ITER_M(m)->type != SDB_ATTRIBUTE)
+ && (ITER_M(m)->type != SDB_FIELD_BACKEND)) {
iter_error(errbuf, m->type, ITER_M(m)->type, context);
return -1;
}
iter_error(errbuf, m->type, ITER_M(m)->type, context);
return -1;
}
- if (analyze_matcher(ITER_M(m)->type, ITER_M(m)->m, errbuf))
+ if (ITER_M(m)->type == SDB_FIELD_BACKEND) {
+ /* array iterators only support simple comparison atm */
+ if ((ITER_M(m)->m->type != MATCHER_LT)
+ && (ITER_M(m)->m->type != MATCHER_LE)
+ && (ITER_M(m)->m->type != MATCHER_EQ)
+ && (ITER_M(m)->m->type != MATCHER_NE)
+ && (ITER_M(m)->m->type != MATCHER_GE)
+ && (ITER_M(m)->m->type != MATCHER_GT)
+ && (ITER_M(m)->m->type != MATCHER_REGEX)
+ && (ITER_M(m)->m->type != MATCHER_NREGEX)) {
+ iter_array_error(errbuf, m->type,
+ CMP_M(ITER_M(m)->m)->left->data_type,
+ ITER_M(m)->m->type,
+ CMP_M(ITER_M(m)->m)->right->data_type);
+ return -1;
+ }
+ if (CMP_M(ITER_M(m)->m)->right->data_type < 0)
+ return 0; /* skip further type checks */
+ if (CMP_M(ITER_M(m)->m)->right->data_type & SDB_TYPE_ARRAY) {
+ iter_array_error(errbuf, m->type,
+ CMP_M(ITER_M(m)->m)->left->data_type,
+ ITER_M(m)->m->type,
+ CMP_M(ITER_M(m)->m)->right->data_type);
+ return -1;
+ }
+ if ((CMP_M(ITER_M(m)->m)->left->data_type & 0xff)
+ != CMP_M(ITER_M(m)->m)->right->data_type) {
+ iter_array_error(errbuf, m->type,
+ CMP_M(ITER_M(m)->m)->left->data_type,
+ ITER_M(m)->m->type,
+ CMP_M(ITER_M(m)->m)->right->data_type);
+ return -1;
+ }
+ }
+ else if (analyze_matcher(ITER_M(m)->type, ITER_M(m)->m, errbuf))
return -1;
break;
/* For now, this function checks basic matcher attributes only;
* later, this may be turned into one of multiple AST visitors. */
- if (node->cmd == CONNECTION_FETCH) {
+ if (node->cmd == SDB_CONNECTION_FETCH) {
conn_fetch_t *fetch = CONN_FETCH(node);
if ((fetch->type == SDB_HOST) && fetch->name) {
sdb_strbuf_sprintf(errbuf, "Unexpected STRING '%s'", fetch->name);
filter = fetch->filter->matcher;
context = fetch->type;
}
- else if (node->cmd == CONNECTION_LIST) {
+ else if (node->cmd == SDB_CONNECTION_LIST) {
if (CONN_LIST(node)->filter)
filter = CONN_LIST(node)->filter->matcher;
context = CONN_LIST(node)->type;
}
- else if (node->cmd == CONNECTION_LOOKUP) {
+ else if (node->cmd == SDB_CONNECTION_LOOKUP) {
if (CONN_LOOKUP(node)->matcher)
m = CONN_LOOKUP(node)->matcher->matcher;
if (CONN_LOOKUP(node)->filter)
filter = CONN_LOOKUP(node)->filter->matcher;
context = CONN_LOOKUP(node)->type;
}
- else if (node->cmd == CONNECTION_TIMESERIES)
+ else if (node->cmd == SDB_CONNECTION_TIMESERIES)
return 0;
else
return -1;