Skip to content

Commit

Permalink
Merge pull request #18 from aceforeverd/feat/add-hybridse-logic-op
Browse files Browse the repository at this point in the history
feat: add hybridse logic op
  • Loading branch information
jingchen2222 authored Jun 8, 2021
2 parents 11e4777 + 450aa08 commit 3676aae
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 19 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
source /opt/rh/rh-python38/enable
bazel test ${{ env.build_argv }} --test_summary=detailed --test_output=errors ${{ env.target }}
linux-build:
runs-on: ubuntu-latest
container:
Expand All @@ -140,26 +140,26 @@ jobs:
source /opt/rh/devtoolset-8/enable
source /opt/rh/rh-python38/enable
bazel build ${{ env.target }} ${{ env.build_argv }}
- name: Test
run: |
bazel test ${{ env.build_argv }} --test_summary=detailed ${{ env.target }}
- name: build zetasql parser dependencies
if: ${{ github.event_name == 'push' }}
run: |
bazel query 'deps(${{ env.target }})' |grep //zetasql|xargs bazel build ${{ env.build_argv }}
bazel query 'deps(${{ env.target }})' |grep //zetasql|xargs bazel build ${{ env.build_argv }}
bazel build "@com_googleapis_googleapis//:all" ${{ env.build_argv }}
bazel build "@com_google_file_based_test_driver//file_based_test_driver:all" ${{ env.build_argv }}
bazel build "@com_googlesource_code_re2//:re2" ${{ env.build_argv }}
- name: Determine Version
if: ${{ github.event_name == 'push' }}
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
VERSION=$(echo $VERSION | sed -e 's/^v//')
echo "TAG=$VERSION" >> $GITHUB_ENV
- name: pack libzetasql
if: ${{ github.event_name == 'push' }}
run: |
Expand Down Expand Up @@ -211,14 +211,14 @@ jobs:
- name: test
run: |
bazel test ${{ env.build_argv }} --test_summary=detailed ${{ env.target }}
- name: Determine Version
if: ${{ github.event_name == 'push' }}
run: |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
VERSION=$(echo $VERSION | sed -e 's/^v//')
echo "TAG=$VERSION" >> $GITHUB_ENV
- name: pack libzetasql
if: ${{ github.event_name == 'push' }}
run: |
Expand All @@ -232,7 +232,7 @@ jobs:
with:
path: libzetasql-*.tar.gz
name: release-artifacts

release:
runs-on: ubuntu-latest
needs: ["linux-build", "macos-build"]
Expand All @@ -252,4 +252,4 @@ jobs:
libzetasql-*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

37 changes: 37 additions & 0 deletions build_zetasql_parser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# build zetasql parser into static library
# Copyright 2021 4Paradigm
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -eE

export BAZEL_LINKOPTS='-static-libstdc++:-lm'
export BAZEL_LINKLIBS='-l%:libstdc++.a'

TARGET='//zetasql/parser/...'
BUILD_ARGV='--features=-supports_dynamic_linker'

bazel build "$TARGET" "$BUILD_ARGV"
bazel test "$TARGET" "$BUILD_ARGV"

# explicitly build dependencies into static library
bazel query "deps($TARGET)" | grep //zetasql | xargs bazel build "$BUILD_ARGV"
bazel build "@com_googleapis_googleapis//:all" "$BUILD_ARGV"
bazel build "@com_google_file_based_test_driver//file_based_test_driver:all" "$BUILD_ARGV"
bazel build "@com_googlesource_code_re2//:re2" "$BUILD_ARGV"

unset BAZEL_LINKLIBS
unset BAZEL_LINKOPTS
14 changes: 13 additions & 1 deletion zetasql/parser/bison_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ class DashedIdentifierTmpNode final : public zetasql::ASTNode {
%token '+' "+"
%token '-' "-"
%token '/' "/"
%token '%' "%"
%token '~' "~"
%token '.' "."
%token KW_DOT_STAR ".*"
Expand Down Expand Up @@ -560,7 +561,7 @@ class DashedIdentifierTmpNode final : public zetasql::ASTNode {
%left "<<" ">>"
%left "+" "-"
%left "||"
%left "*" "/"
%left "*" "/" "DIV" "%" "MOD"
%left UNARY_PRECEDENCE // For all unary operators
%precedence DOUBLE_AT_PRECEDENCE // Needs to appear before "."
%left PRIMARY_PRECEDENCE "(" ")" "[" "]" "." // For ., .(...), [], etc.
Expand Down Expand Up @@ -671,6 +672,7 @@ using zetasql::ASTDropStatement;
%token KW_DEFINE "DEFINE"
%token KW_DESC "DESC"
%token KW_DISTINCT "DISTINCT"
%token KW_IDIVIDE "DIV"
%token KW_ELSE "ELSE"
%token KW_END "END"
%token KW_ENUM "ENUM"
Expand Down Expand Up @@ -710,6 +712,7 @@ using zetasql::ASTDropStatement;
%token KW_LIMIT "LIMIT"
%token KW_LOOKUP "LOOKUP"
%token KW_MERGE "MERGE"
%token KW_MOD "MOD"
%token KW_NATURAL "NATURAL"
%token KW_NEW "NEW"
%token KW_NO "NO"
Expand Down Expand Up @@ -5225,6 +5228,9 @@ additive_operator:
multiplicative_operator:
"*" { $$ = zetasql::ASTBinaryExpression::MULTIPLY; }
| "/" { $$ = zetasql::ASTBinaryExpression::DIVIDE; }
| "DIV" { $$ = zetasql::ASTBinaryExpression::IDIVIDE; }
| "%" { $$ = zetasql::ASTBinaryExpression::MOD; }
| "MOD" { $$ = zetasql::ASTBinaryExpression::MOD; }
;

// Returns ShiftOperator to indicate the operator type.
Expand Down Expand Up @@ -6351,6 +6357,10 @@ function_name_from_keyword:
{
$$ = parser->MakeIdentifier(@1, parser->GetInputText(@1));
}
| "MOD"
{
$$ = parser->MakeIdentifier(@1, parser->GetInputText(@1));
}
;

// These rules have "expression" as their first part rather than
Expand Down Expand Up @@ -7074,6 +7084,7 @@ reserved_keyword_rule:
| "DEFINE"
| "DESC"
| "DISTINCT"
| "DIV"
| "ELSE"
| "END"
| "ENUM"
Expand Down Expand Up @@ -7105,6 +7116,7 @@ reserved_keyword_rule:
| "LIMIT"
| "LOOKUP"
| "MERGE"
| "MOD"
| "NATURAL"
| "NEW"
| "NOT"
Expand Down
14 changes: 13 additions & 1 deletion zetasql/parser/flex_tokenizer.l
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ pound_comment #[^\r\n]*(\r|\n|\r\n)?

comment ({cs_comment}|{dash_comment}|{pound_comment})

not (not|"!")

%%
/* RULES SECTION
Expand Down Expand Up @@ -416,6 +418,7 @@ descriptor { return BisonParserImpl::token::KW_DESCRIPTOR; }
describe { return BisonParserImpl::token::KW_DESCRIBE; }
deterministic { return BisonParserImpl::token::KW_DETERMINISTIC; }
distinct { return BisonParserImpl::token::KW_DISTINCT; }
div { return BisonParserImpl::token::KW_IDIVIDE; }
do { return BisonParserImpl::token::KW_DO; }
drop { return BisonParserImpl::token::KW_DROP; }
else { return BisonParserImpl::token::KW_ELSE; }
Expand Down Expand Up @@ -512,12 +515,13 @@ maxsize { return BisonParserImpl::token::KW_MAXSIZE; }
merge { return BisonParserImpl::token::KW_MERGE; }
message { return BisonParserImpl::token::KW_MESSAGE; }
min { return BisonParserImpl::token::KW_MIN; }
mod { return BisonParserImpl::token::KW_MOD; }
model { return BisonParserImpl::token::KW_MODEL; }
module { return BisonParserImpl::token::KW_MODULE; }
natural { return BisonParserImpl::token::KW_NATURAL; }
new { return BisonParserImpl::token::KW_NEW; }
no { return BisonParserImpl::token::KW_NO; }
not { return BisonParserImpl::token::KW_NOT; }
{not} { return BisonParserImpl::token::KW_NOT; }
/* This returns a different token because returning KW_NOT would confuse the
operator precedence parsing. Boolean NOT has a different precedence than
NOT BETWEEN/IN/LIKE/DISTINCT. The final character at the end is intended to
Expand All @@ -533,6 +537,13 @@ not{whitespace}(between|in|like|distinct)[^A-Z_0-9] {
}
return BisonParserImpl::token::KW_NOT_SPECIAL;
}
"!"{whitespace}(between|in|like|distinct)[^A-Z_0-9] {
SET_RETURN_PREFIX_LENGTH(1);
if (mode_ == BisonParserMode::kTokenizer) {
return BisonParserImpl::token::KW_NOT;
}
return BisonParserImpl::token::KW_NOT_SPECIAL;
}
null { return BisonParserImpl::token::KW_NULL; }
nulls { return BisonParserImpl::token::KW_NULLS; }
numeric { return BisonParserImpl::token::KW_NUMERIC; }
Expand Down Expand Up @@ -868,6 +879,7 @@ zone { return BisonParserImpl::token::KW_ZONE; }
"+" { return '+'; }
"-" { return '-'; }
"/" { return '/'; }
"%" { return '%'; }
"~" { return '~'; }
"?" { return '?'; }
"@"{opt_whitespace}"{" {
Expand Down
2 changes: 2 additions & 0 deletions zetasql/parser/keywords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"descriptor", KW_DESCRIPTOR},
{"deterministic", KW_DETERMINISTIC},
{"distinct", KW_DISTINCT, KeywordInfo::kReserved},
{"div", KW_IDIVIDE, KeywordInfo::kReserved},
{"do", KW_DO},
{"drop", KW_DROP},
{"else", KW_ELSE, KeywordInfo::kReserved},
Expand Down Expand Up @@ -190,6 +191,7 @@ constexpr KeywordInfoPOD kAllKeywords[] = {
{"maxsize", KW_MAXSIZE},
{"message", KW_MESSAGE},
{"min", KW_MIN},
{"mod", KW_MOD, KeywordInfo::kReserved},
{"model", KW_MODEL},
{"module", KW_MODULE},
{"merge", KW_MERGE, KeywordInfo::kReserved},
Expand Down
2 changes: 1 addition & 1 deletion zetasql/parser/keywords_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ TEST(ParserTest, DontAddNewReservedKeywords) {
// allows new queries to work that will not work on older code.
// Before changing this, co-ordinate with all engines to make sure the change
// is done safely.
EXPECT_EQ(100 /* CAUTION */, num_reserved);
EXPECT_EQ(102 /* CAUTION */, num_reserved);
}

} // namespace
Expand Down
4 changes: 4 additions & 0 deletions zetasql/parser/parse_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ std::string ASTBinaryExpression::GetSQLForOperator() const {
return "*";
case DIVIDE:
return "/";
case IDIVIDE:
return "DIV";
case MOD:
return "%";
case CONCAT_OP:
return "||";
case DISTINCT:
Expand Down
2 changes: 2 additions & 0 deletions zetasql/parser/parse_tree_manual.h
Original file line number Diff line number Diff line change
Expand Up @@ -1838,6 +1838,8 @@ class ASTBinaryExpression final : public ASTExpression {
MINUS, // "-"
MULTIPLY, // "*"
DIVIDE, // "/"
IDIVIDE, // "div", integer division
MOD, // "%"
CONCAT_OP, // "||"
DISTINCT, // "IS DISTINCT FROM"
};
Expand Down
2 changes: 1 addition & 1 deletion zetasql/parser/testdata/bitwise_operators.test
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ select 1 < > 2
--
ALTERNATION GROUP: ! =
--
ERROR: Syntax error: Illegal input character "!" [at 1:10]
ERROR: Syntax error: Expected end of input but got keyword NOT [at 1:10]
select 1 ! = 2
^
==
Expand Down
4 changes: 2 additions & 2 deletions zetasql/parser/testdata/create_materialized_view.test
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ CreateMaterializedViewStatement [0-109]
ClusterBy [68-89]
FunctionCall [79-89]
PathExpression [79-82]
Identifier(mod) [79-82]
Identifier(`mod`) [79-82]
PathExpression [83-85]
Identifier(c1) [83-85]
IntLiteral(2) [87-88]
Expand All @@ -165,7 +165,7 @@ CreateMaterializedViewStatement [0-109]
PathExpression [107-109]
Identifier(t2) [107-109]
--
CREATE MATERIALIZED VIEW mv PARTITION BY c1, c2 + CAST(c3 AS int64) CLUSTER BY mod(c1, 2) AS
CREATE MATERIALIZED VIEW mv PARTITION BY c1, c2 + CAST(c3 AS int64) CLUSTER BY `mod`(c1, 2) AS
SELECT
*
FROM
Expand Down
Loading

0 comments on commit 3676aae

Please sign in to comment.