Compare commits
3 Commits
a8efef907a
...
35b5c1b41b
Author | SHA1 | Date | |
---|---|---|---|
35b5c1b41b | |||
8f3ec93f82 | |||
34ccc51b79 |
@ -24,6 +24,9 @@ rule read_token = parse
|
||||
| "ON" { ON }
|
||||
| "WHERE" { WHERE }
|
||||
| "HAVING" { HAVING }
|
||||
| "BETWEEN" { BETWEEN }
|
||||
| "IN" { IN }
|
||||
| "LIKE" { LIKE }
|
||||
| "GROUP" { GROUP }
|
||||
| "BY" { BY }
|
||||
| "*" { ASTERISK }
|
||||
@ -32,6 +35,7 @@ rule read_token = parse
|
||||
| "(" { LEFT_PAREN }
|
||||
| ")" { RIGHT_PAREN }
|
||||
| "," { COMMA }
|
||||
| "|" { PIPE }
|
||||
| whitespace { read_token lexbuf }
|
||||
| alpha alphanumeric* as ident { IDENT ident }
|
||||
| eof { EOF }
|
||||
|
42
lib/ast.ml
42
lib/ast.ml
@ -26,6 +26,7 @@ and predicate =
|
||||
| NotBetween of string * string
|
||||
| In of string list
|
||||
| NotIn of string list
|
||||
| Like of string
|
||||
and operator =
|
||||
| Equals
|
||||
| NotEquals
|
||||
@ -37,3 +38,44 @@ and filter =
|
||||
| Filter of string
|
||||
and search_condition =
|
||||
| Search of string
|
||||
|
||||
|
||||
let rec pp_query ast =
|
||||
match ast with
|
||||
| Query(s) -> pp_select s
|
||||
|
||||
and pp_select s =
|
||||
match s with
|
||||
| Select(cols, _) -> pp_columns cols
|
||||
|
||||
and pp_columns cols =
|
||||
match cols with
|
||||
| [] -> ""
|
||||
| [col] -> pp_column col
|
||||
| col::l -> pp_column col ^ ";" ^ pp_columns l
|
||||
|
||||
and pp_column col =
|
||||
match col with
|
||||
| Column(name) -> name
|
||||
| Asterisk -> "*"
|
||||
|
||||
and pp_tables tables =
|
||||
match tables with
|
||||
| [] -> ""
|
||||
| [table] -> pp_table table
|
||||
| table::l -> pp_table table ^ ";" ^ pp_tables l
|
||||
|
||||
and pp_table table =
|
||||
match table with
|
||||
| Table(table) -> table
|
||||
| Join(t1, j, t2, _) -> pp_table t1 ^ pp_join_type j ^ pp_table t2
|
||||
|
||||
and pp_join_type j =
|
||||
match j with
|
||||
| Inner -> "inner"
|
||||
| Left -> "left"
|
||||
| Right -> "right"
|
||||
| Full -> "full"
|
||||
| Cross -> "cross"
|
||||
| Union -> "union"
|
||||
| Natural -> "natural"
|
||||
|
@ -4,14 +4,14 @@ open Ast
|
||||
%}
|
||||
|
||||
%token CREATE TABLE
|
||||
%token SELECT ALL DISTINCT FROM WHERE HAVING BETWEEN IN
|
||||
%token SELECT ALL DISTINCT FROM WHERE HAVING BETWEEN IN LIKE
|
||||
%token LEFT RIGHT FULL INNER OUTER
|
||||
%token CROSS NATURAL UNION JOIN
|
||||
%token CROSS NATURAL UNION JOIN
|
||||
%token GREATER_THAN_OPERATOR LESS_THAN_OPERATOR EQUALS_OPERATOR
|
||||
%token MAX MIN SUM COUNT AVG
|
||||
%token ASYMMETRIC SYMMETRIC
|
||||
%token <string> IDENT
|
||||
%token COMMA DOT
|
||||
%token COMMA DOT PIPE
|
||||
%token LEFT_PAREN RIGHT_PAREN
|
||||
%token ASTERISK
|
||||
%token AS ON GROUP BY FILTER
|
||||
@ -165,7 +165,7 @@ predicate :
|
||||
| comparison_predicate { $1 }
|
||||
| between_predicate { $1 }
|
||||
| in_predicate { $1 }
|
||||
| like_predicate { $1 }
|
||||
(* | like_predicate { $1 } *)
|
||||
|
||||
comparison_predicate :
|
||||
| row_value_predicand comparison_predicate_part2 { Condition($1, $2) }
|
||||
@ -199,6 +199,36 @@ in_value_list:
|
||||
| row_value_expression { [$1] }
|
||||
| in_value_list COMMA row_value_expression { $3::$1 }
|
||||
|
||||
like_predicate :
|
||||
| character_like_predicate { $1 }
|
||||
|
||||
character_like_predicate :
|
||||
| row_value_predicand character_like_predicate_part2 { }
|
||||
|
||||
character_like_predicate_part2:
|
||||
| LIKE character_pattern {}
|
||||
| NOT LIKE character_pattern {}
|
||||
|
||||
character_pattern :
|
||||
| character_value_expression {}
|
||||
|
||||
character_value_expression:
|
||||
| concatenation {}
|
||||
| character_factor {}
|
||||
|
||||
concatenation:
|
||||
| character_value_expression concatenation_operator character_factor {}
|
||||
|
||||
character_factor :
|
||||
| character_primary {}
|
||||
|
||||
character_primary:
|
||||
| value_expression_primary {}
|
||||
(* | string_value_function {} *)
|
||||
|
||||
concatenation_operator:
|
||||
| PIPE PIPE {}
|
||||
|
||||
row_value_expression :
|
||||
| row_value_special_case { $1 }
|
||||
|
||||
|
15
test/test_ast.ml
Normal file
15
test/test_ast.ml
Normal file
@ -0,0 +1,15 @@
|
||||
open Ast
|
||||
|
||||
let parse query =
|
||||
let lexbuf = Lexing.from_string query in
|
||||
Parser.main Lexer.read_token lexbuf
|
||||
|
||||
let equal_ast ast1 ast2 =
|
||||
ast1 = ast2
|
||||
|
||||
let
|
||||
|
||||
let test_simple_select() =
|
||||
let q1 = parse "SELECT a FROM t" in
|
||||
let ast1 = Query(Select([Column("a")], [Table("t")])) in
|
||||
Alcotest.(check
|
0
thrift/dune
Normal file
0
thrift/dune
Normal file
3364
thrift/hive_metastore.thrift
Normal file
3364
thrift/hive_metastore.thrift
Normal file
File diff suppressed because it is too large
Load Diff
113
thrift/share/fb303/if/fb303.thrift
Normal file
113
thrift/share/fb303/if/fb303.thrift
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* fb303.thrift
|
||||
*/
|
||||
|
||||
namespace java com.facebook.fb303
|
||||
namespace cpp facebook.fb303
|
||||
namespace perl Facebook.FB303
|
||||
namespace netstd Facebook.FB303.Test
|
||||
|
||||
/**
|
||||
* Common status reporting mechanism across all services
|
||||
*/
|
||||
enum fb_status {
|
||||
DEAD = 0,
|
||||
STARTING = 1,
|
||||
ALIVE = 2,
|
||||
STOPPING = 3,
|
||||
STOPPED = 4,
|
||||
WARNING = 5,
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard base service
|
||||
*/
|
||||
service FacebookService {
|
||||
|
||||
/**
|
||||
* Returns a descriptive name of the service
|
||||
*/
|
||||
string getName(),
|
||||
|
||||
/**
|
||||
* Returns the version of the service
|
||||
*/
|
||||
string getVersion(),
|
||||
|
||||
/**
|
||||
* Gets the status of this service
|
||||
*/
|
||||
fb_status getStatus(),
|
||||
|
||||
/**
|
||||
* User friendly description of status, such as why the service is in
|
||||
* the dead or warning state, or what is being started or stopped.
|
||||
*/
|
||||
string getStatusDetails(),
|
||||
|
||||
/**
|
||||
* Gets the counters for this service
|
||||
*/
|
||||
map<string, i64> getCounters(),
|
||||
|
||||
/**
|
||||
* Gets the value of a single counter
|
||||
*/
|
||||
i64 getCounter(1: string key),
|
||||
|
||||
/**
|
||||
* Sets an option
|
||||
*/
|
||||
void setOption(1: string key, 2: string value),
|
||||
|
||||
/**
|
||||
* Gets an option
|
||||
*/
|
||||
string getOption(1: string key),
|
||||
|
||||
/**
|
||||
* Gets all options
|
||||
*/
|
||||
map<string, string> getOptions(),
|
||||
|
||||
/**
|
||||
* Returns a CPU profile over the given time interval (client and server
|
||||
* must agree on the profile format).
|
||||
*/
|
||||
string getCpuProfile(1: i32 profileDurationInSec),
|
||||
|
||||
/**
|
||||
* Returns the unix time that the server has been running since
|
||||
*/
|
||||
i64 aliveSince(),
|
||||
|
||||
/**
|
||||
* Tell the server to reload its configuration, reopen log files, etc
|
||||
*/
|
||||
oneway void reinitialize(),
|
||||
|
||||
/**
|
||||
* Suggest a shutdown to the server
|
||||
*/
|
||||
oneway void shutdown(),
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user