You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2016/11/25 13:34:19 UTC
[3/5] incubator-trafodion git commit: [TRAFODION-2353] support of the
regexp operator, execution and test case
[TRAFODION-2353] support of the regexp operator, execution and test case
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/257a7a46
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/257a7a46
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/257a7a46
Branch: refs/heads/master
Commit: 257a7a46426f279b35d3d00cc2be8089713bb5a0
Parents: 4355adf
Author: Liu Ming <ov...@sina.com>
Authored: Fri Nov 18 22:48:58 2016 -0500
Committer: Liu Ming <ov...@sina.com>
Committed: Fri Nov 18 22:48:58 2016 -0500
----------------------------------------------------------------------
core/sql/exp/exp_like.cpp | 39 +++++++----
core/sql/regress/executor/EXPECTED002.SB | 94 +++++++++++++++++++++++++--
core/sql/regress/executor/TEST002 | 28 +++++++-
3 files changed, 140 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/257a7a46/core/sql/exp/exp_like.cpp
----------------------------------------------------------------------
diff --git a/core/sql/exp/exp_like.cpp b/core/sql/exp/exp_like.cpp
index 4409fc1..845c27d 100644
--- a/core/sql/exp/exp_like.cpp
+++ b/core/sql/exp/exp_like.cpp
@@ -506,33 +506,46 @@ ex_expr::exp_return_type ExRegexpClauseChar::eval(char *op_data[],
CollHeap* exHeap,
ComDiagsArea** diagsArea)
{
-//comehere
+ NABoolean matchFlag = true;
Lng32 len1 = getOperand(1)->getLength(op_data[-MAX_OPERANDS+1]);
Lng32 len2 = getOperand(2)->getLength(op_data[-MAX_OPERANDS+2]);
regex_t reg;
- regmatch_t pm[10];
- const size_t nmatch = 10;
- int cflags, z;
- cflags = REG_EXTENDED|REG_NEWLINE;
+ regmatch_t pm[1];
+ const size_t nmatch = 1;
+ Lng32 cflags, z;
char * pattern;
- pattern = new (exHeap) char[len2];
- char *srcStr= new (exHeap) char[len1];
- memcpy(pattern, op_data[2], len2);
- memcpy(srcStr, op_data[1], len1);
+ char *srcStr= new (exHeap) char[len1+1];
+
+ cflags = REG_EXTENDED|REG_NEWLINE;
+ pattern = new (exHeap) char[len2+1];
+ pattern[len2]=0;
+ srcStr[len1]=0;
+
+ str_cpy_all(pattern, op_data[2], len2);
+ str_cpy_all(srcStr, op_data[1], len1);
+
z = regcomp(®, pattern, cflags);
+
if (z != 0){
//ERROR
+ ExRaiseSqlError(exHeap, diagsArea, EXE_BAD_ARG_TO_MATH_FUNC);
+ **diagsArea << DgString0("REGEXP");
return ex_expr::EXPR_ERROR;
}
-
- NABoolean matchFlag = true;
+
z = regexec(®,srcStr , nmatch, pm, 0);
- if (z == REG_NOMATCH)
+ if (z != 0)
matchFlag = false;
-
+
*(Lng32 *)op_data[0] = (Lng32)matchFlag;
+ regfree(®);
+
+ NADELETEBASIC(pattern, exHeap);
+ NADELETEBASIC(srcStr, exHeap);
+
return ex_expr::EXPR_OK;
}
+
ex_expr::exp_return_type ex_like_clause_char::eval(char *op_data[],
CollHeap* exHeap,
ComDiagsArea** diagsArea)
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/257a7a46/core/sql/regress/executor/EXPECTED002.SB
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/EXPECTED002.SB b/core/sql/regress/executor/EXPECTED002.SB
index 451eda1..f8e5e0b 100644
--- a/core/sql/regress/executor/EXPECTED002.SB
+++ b/core/sql/regress/executor/EXPECTED002.SB
@@ -6640,7 +6640,7 @@ A B C E
+> GROUP_CONCAT(DISTINCT test_score
+> ORDER BY test_score SEPARATOR '-')
+> FROM student
-+> GROUP BY student_name;
++> GROUP BY student_name order by student_name;
STUDENT_NAME (EXPR)
------------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------
@@ -6655,7 +6655,7 @@ s3 40-90-100
+> GROUP_CONCAT(test_score
+> ORDER BY test_score SEPARATOR '-')
+> FROM student
-+> GROUP BY student_name;
++> GROUP BY student_name order by student_name;
STUDENT_NAME (EXPR)
------------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------
@@ -6676,7 +6676,7 @@ s3 40-40-90-100
+> GROUP_CONCAT(DISTINCT test_score
+> ORDER BY test_score desc SEPARATOR '-')
+> FROM student
-+> GROUP BY student_name;
++> GROUP BY student_name order by student_name;
--- SQL command prepared.
>>explain options 'f' s1;
@@ -6685,7 +6685,7 @@ LC RC OP OPERATOR OPT DESCRIPTION CARD
---- ---- ---- -------------------- -------- -------------------- ---------
7 . 8 root 2.00E+000
-6 . 7 esp_exchange 1:2(hash2) 2.00E+000
+6 . 7 esp_exchange 1:2(hash2) (m) 2.00E+000
5 . 6 sort_groupby 2.00E+000
4 . 5 sort_partial_groupby 4.00E+000
3 . 4 sort 4.00E+000
@@ -6699,8 +6699,8 @@ LC RC OP OPERATOR OPT DESCRIPTION CARD
STUDENT_NAME (EXPR)
------------ -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------
-s2 188-88-58-18
s1 101-100-88-79-60-50-40
+s2 188-88-58-18
s3 100-90-40
--- 3 row(s) selected.
@@ -6713,6 +6713,90 @@ s3 100-90-40
>>drop table student;
--- SQL operation complete.
+>>drop table if exists regexp_test;
+
+--- SQL operation complete.
+>>create table regexp_test (c1 char(32) );
+
+--- SQL operation complete.
+>>insert into regexp_test values( '123' );
+
+--- 1 row(s) inserted.
+>>insert into regexp_test values( '123a' );
+
+--- 1 row(s) inserted.
+>>insert into regexp_test values( 'english' );
+
+--- 1 row(s) inserted.
+>>insert into regexp_test values( 'dev@TRAFODION.org' );
+
+--- 1 row(s) inserted.
+>>insert into regexp_test values( '127.0.0.1' );
+
+--- 1 row(s) inserted.
+>>insert into regexp_test values( '127.0.0.300' );
+
+--- 1 row(s) inserted.
+>>insert into regexp_test values('\u4e2d\u6587\u6d4b\u8bd5');
+
+--- 1 row(s) inserted.
+>>
+>>-- only number
+>>select * from regexp_test where c1 regexp '^[0-9]*\s*$';
+
+C1
+----------
+
+123
+
+--- 1 row(s) selected.
+>>select * from regexp_test where c1 regexp '^[[:digit:]]*\s*$';
+
+C1
+----------
+
+123
+
+--- 1 row(s) selected.
+>>-- only english
+>>select * from regexp_test where c1 regexp '^.[A-Za-z]+\s*$';
+
+C1
+----------
+
+english
+
+--- 1 row(s) selected.
+>>-- valid email address
+>>select * from regexp_test where c1 regexp '\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*';
+
+C1
+----------
+
+dev@TRAFODION.org
+
+--- 1 row(s) selected.
+>>-- valid ip address
+>>select * from regexp_test where c1 regexp '^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])\s*$';
+
+C1
+----------
+
+127.0.0.1
+
+--- 1 row(s) selected.
+>>-- utf-8 code
+>>select * from regexp_test where c1 regexp '[\u4e2d\u6587\u6d4b\u8bd5]';
+
+C1
+----------
+
+\u4e2d\u6587\u6d4b\u8bd5
+
+--- 1 row(s) selected.
+>>drop table regexp_test;
+
+--- SQL operation complete.
>>------------------------------------------------------------------------
>>
>>obey TEST002(BR0198_MULTI);
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/257a7a46/core/sql/regress/executor/TEST002
----------------------------------------------------------------------
diff --git a/core/sql/regress/executor/TEST002 b/core/sql/regress/executor/TEST002
index bfddf5d..d79c97d 100755
--- a/core/sql/regress/executor/TEST002
+++ b/core/sql/regress/executor/TEST002
@@ -1111,13 +1111,13 @@ SELECT student_name,
GROUP_CONCAT(DISTINCT test_score
ORDER BY test_score SEPARATOR '-')
FROM student
- GROUP BY student_name;
+ GROUP BY student_name order by student_name;
SELECT student_name,
GROUP_CONCAT(test_score
ORDER BY test_score SEPARATOR '-')
FROM student
- GROUP BY student_name;
+ GROUP BY student_name order by student_name;
cqd ATTEMPT_ESP_PARALLELISM 'ON';
control query shape exchange(cut);
@@ -1125,12 +1125,34 @@ prepare s1 from SELECT student_name,
GROUP_CONCAT(DISTINCT test_score
ORDER BY test_score desc SEPARATOR '-')
FROM student
- GROUP BY student_name;
+ GROUP BY student_name order by student_name;
explain options 'f' s1;
execute s1;
control query shape cut;
cqd ATTEMPT_ESP_PARALLELISM 'OFF';
drop table student;
+drop table if exists regexp_test;
+create table regexp_test (c1 char(32) );
+insert into regexp_test values( '123' );
+insert into regexp_test values( '123a' );
+insert into regexp_test values( 'english' );
+insert into regexp_test values( 'dev@trafodion.org' );
+insert into regexp_test values( '127.0.0.1' );
+insert into regexp_test values( '127.0.0.300' );
+insert into regexp_test values('\u4e2d\u6587\u6d4b\u8bd5');
+
+-- only number
+select * from regexp_test where c1 regexp '^[0-9]*\s*$';
+select * from regexp_test where c1 regexp '^[[:digit:]]*\s*$';
+-- only english
+select * from regexp_test where c1 regexp '^.[A-Za-z]+\s*$';
+-- valid email address
+select * from regexp_test where c1 regexp '\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*';
+-- valid ip address
+select * from regexp_test where c1 regexp '^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])\s*$';
+-- utf-8 code
+select * from regexp_test where c1 regexp '[\u4e2d\u6587\u6d4b\u8bd5]';
+drop table regexp_test;
------------------------------------------------------------------------
obey TEST002(BR0198_MULTI);