Skip to content

Commit f278982

Browse files
committed
processor_sql: parser: add missing tokens for conditional ops
Signed-off-by: Eduardo Silva <[email protected]>
1 parent e3f6252 commit f278982

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

plugins/processor_sql/parser/sql-parser.l

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ NOT return NOT;
6060
IS return IS;
6161
NULL return NUL;
6262

63-
-?[1-9][0-9]*|0 { yylval->integer = atoi(yytext); return INTEGER; }
63+
"true" { yylval->boolean = true; return BOOLTYPE; };
64+
"false" { yylval->boolean = false; return BOOLTYPE; };
65+
66+
-?[1-9][0-9]*|0 { yylval->integer = atol(yytext); return INTEGER; }
6467
(-?[1-9][0-9]*|0)\.[0-9]+ { yylval->fval = atof(yytext); return FLOATING; }
6568
\'([^']|'{2})*\' { yylval->string = remove_dup_qoutes(yytext + 1, yyleng - 2); return STRING; }
6669
[_A-Za-z][A-Za-z0-9_.]* { yylval->string = flb_strdup(yytext); return IDENTIFIER; }
@@ -72,6 +75,13 @@ NULL return NUL;
7275
")" |
7376
";" { return yytext[0]; }
7477

78+
"!=" return NEQ;
79+
"<>" return NEQ;
80+
"<" return LT;
81+
"<=" return LTE;
82+
">" return GT;
83+
">=" return GTE;
84+
7585
\' return QUOTE;
7686
\n
7787
[ \t]+ /* ignore whitespace */;

plugins/processor_sql/parser/sql-parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,14 @@ select: SELECT keys FROM source where ';'
161161
// {
162162
// flb_free($1);
163163
// }
164-
value: INTEGER
164+
value: INTEGER
165165
{
166166
$$ = sql_expression_condition_integer(query, $1);
167167
}
168168
|
169169
FLOATING
170170
{
171+
171172
$$ = sql_expression_condition_float(query, $1);
172173
}
173174
|
@@ -213,7 +214,6 @@ select: SELECT keys FROM source where ';'
213214
|
214215
record_func '=' value
215216
{
216-
printf("record_func '=' value\n");
217217
$$ = sql_expression_comparison(query, $1, $3, SQL_EXP_EQ);
218218
}
219219
|

plugins/processor_sql/parser/sql_expression.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ struct sql_expression *sql_expression_condition_float(struct sql_query *query,
129129
}
130130

131131
val->type = SQL_EXP_FLOAT;
132-
val->val.i64 = fval;
132+
val->val.f64 = fval;
133133
cfl_list_add(&val->_head, &query->cond_list);
134134

135135
return (struct sql_expression *) val;
@@ -148,6 +148,12 @@ struct sql_expression *sql_expression_condition_string(struct sql_query *query,
148148

149149
val->type = SQL_EXP_STRING;
150150
val->val.string = cfl_sds_create(string);
151+
if (!val->val.string) {
152+
flb_errno();
153+
flb_free(val);
154+
return NULL;
155+
}
156+
151157
cfl_list_add(&val->_head, &query->cond_list);
152158

153159
return (struct sql_expression *) val;
@@ -208,4 +214,4 @@ struct sql_expression *sql_expression_comparison(struct sql_query *query,
208214
cfl_list_add(&expression->_head, &query->cond_list);
209215

210216
return (struct sql_expression *) expression;
211-
}
217+
}

0 commit comments

Comments
 (0)