Skip to content

Commit

Permalink
Feat/collect entity hive (#263)
Browse files Browse the repository at this point in the history
* feat(hive): support hive collect entity

* feat(hive): update tableAllColumns
  • Loading branch information
LuckyFBB authored Feb 26, 2024
1 parent 5d760d7 commit 952727d
Show file tree
Hide file tree
Showing 13 changed files with 8,409 additions and 7,465 deletions.
51 changes: 22 additions & 29 deletions src/grammar/hive/HiveSqlParser.g4
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
/**
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.
*/
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.
*/

/**
* This file is an adaptation of antlr/grammars-v4's sql/hive/v4/HiveParser.g4 grammar.
* Reference: https://github.com/antlr/grammars-v4/blob/master/sql/hive/v4/HiveParser.g4
* This file is an adaptation of antlr/grammars-v4's sql/hive/v4/HiveParser.g4 grammar. Reference:
* https://github.com/antlr/grammars-v4/blob/master/sql/hive/v4/HiveParser.g4
*/

// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
Expand Down Expand Up @@ -1095,7 +1093,10 @@ fromStatement
;

singleFromStatement
: fromClause b+=body+
: fromClause insertClause selectClause lateralView? whereClause? groupByClause? havingClause? window_clause? qualifyClause? orderByClause?
clusterByClause? distributeByClause? sortByClause? limitClause? # fromInsertStmt
| fromClause selectClause lateralView? whereClause? groupByClause? havingClause? window_clause? qualifyClause? orderByClause? clusterByClause?
distributeByClause? sortByClause? limitClause? # fromSelectStmt
;

/*
Expand All @@ -1105,8 +1106,8 @@ The valuesClause rule below ensures that the parse tree for
very similar to the tree for "insert into table FOO select a,b from BAR".
*/
regularBody
: i=insertClause s=selectStatement
| selectStatement
: i=insertClause s=selectStatement # insertStmt
| selectStatement # selectStmt
;

atomSelectStatement
Expand All @@ -1127,13 +1128,6 @@ selectStatementWithCTE
: w=withClause? selectStatement
;

body
: insertClause selectClause lateralView? whereClause? groupByClause? havingClause? window_clause? qualifyClause? orderByClause? clusterByClause?
distributeByClause? sortByClause? limitClause?
| selectClause lateralView? whereClause? groupByClause? havingClause? window_clause? qualifyClause? orderByClause? clusterByClause?
distributeByClause? sortByClause? limitClause?
;

insertClause
: KW_INSERT (
KW_OVERWRITE destination ifNotExists?
Expand Down Expand Up @@ -1666,8 +1660,7 @@ dropDataConnectorStatement
;

tableAllColumns
: STAR
| tableOrView DOT STAR
: (id_ DOT)* STAR
;

defaultValue
Expand Down
3 changes: 1 addition & 2 deletions src/lib/hive/HiveSqlParser.interp

Large diffs are not rendered by default.

14,810 changes: 7,417 additions & 7,393 deletions src/lib/hive/HiveSqlParser.ts

Large diffs are not rendered by default.

68 changes: 56 additions & 12 deletions src/lib/hive/HiveSqlParserListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener";

import { FromInsertStmtContext } from "./HiveSqlParser";
import { FromSelectStmtContext } from "./HiveSqlParser";
import { InsertStmtContext } from "./HiveSqlParser";
import { SelectStmtContext } from "./HiveSqlParser";
import { ProgramContext } from "./HiveSqlParser";
import { StatementContext } from "./HiveSqlParser";
import { ExplainStatementContext } from "./HiveSqlParser";
Expand Down Expand Up @@ -210,7 +214,6 @@ import { AtomSelectStatementContext } from "./HiveSqlParser";
import { SelectStatementContext } from "./HiveSqlParser";
import { SetOpSelectStatementContext } from "./HiveSqlParser";
import { SelectStatementWithCTEContext } from "./HiveSqlParser";
import { BodyContext } from "./HiveSqlParser";
import { InsertClauseContext } from "./HiveSqlParser";
import { DestinationContext } from "./HiveSqlParser";
import { LimitClauseContext } from "./HiveSqlParser";
Expand Down Expand Up @@ -531,6 +534,58 @@ import { DropMappingStatementContext } from "./HiveSqlParser";
* `HiveSqlParser`.
*/
export interface HiveSqlParserListener extends ParseTreeListener {
/**
* Enter a parse tree produced by the `fromInsertStmt`
* labeled alternative in `HiveSqlParser.singleFromStatement`.
* @param ctx the parse tree
*/
enterFromInsertStmt?: (ctx: FromInsertStmtContext) => void;
/**
* Exit a parse tree produced by the `fromInsertStmt`
* labeled alternative in `HiveSqlParser.singleFromStatement`.
* @param ctx the parse tree
*/
exitFromInsertStmt?: (ctx: FromInsertStmtContext) => void;

/**
* Enter a parse tree produced by the `fromSelectStmt`
* labeled alternative in `HiveSqlParser.singleFromStatement`.
* @param ctx the parse tree
*/
enterFromSelectStmt?: (ctx: FromSelectStmtContext) => void;
/**
* Exit a parse tree produced by the `fromSelectStmt`
* labeled alternative in `HiveSqlParser.singleFromStatement`.
* @param ctx the parse tree
*/
exitFromSelectStmt?: (ctx: FromSelectStmtContext) => void;

/**
* Enter a parse tree produced by the `insertStmt`
* labeled alternative in `HiveSqlParser.regularBody`.
* @param ctx the parse tree
*/
enterInsertStmt?: (ctx: InsertStmtContext) => void;
/**
* Exit a parse tree produced by the `insertStmt`
* labeled alternative in `HiveSqlParser.regularBody`.
* @param ctx the parse tree
*/
exitInsertStmt?: (ctx: InsertStmtContext) => void;

/**
* Enter a parse tree produced by the `selectStmt`
* labeled alternative in `HiveSqlParser.regularBody`.
* @param ctx the parse tree
*/
enterSelectStmt?: (ctx: SelectStmtContext) => void;
/**
* Exit a parse tree produced by the `selectStmt`
* labeled alternative in `HiveSqlParser.regularBody`.
* @param ctx the parse tree
*/
exitSelectStmt?: (ctx: SelectStmtContext) => void;

/**
* Enter a parse tree produced by `HiveSqlParser.program`.
* @param ctx the parse tree
Expand Down Expand Up @@ -2808,17 +2863,6 @@ export interface HiveSqlParserListener extends ParseTreeListener {
*/
exitSelectStatementWithCTE?: (ctx: SelectStatementWithCTEContext) => void;

/**
* Enter a parse tree produced by `HiveSqlParser.body`.
* @param ctx the parse tree
*/
enterBody?: (ctx: BodyContext) => void;
/**
* Exit a parse tree produced by `HiveSqlParser.body`.
* @param ctx the parse tree
*/
exitBody?: (ctx: BodyContext) => void;

/**
* Enter a parse tree produced by `HiveSqlParser.insertClause`.
* @param ctx the parse tree
Expand Down
44 changes: 36 additions & 8 deletions src/lib/hive/HiveSqlParserVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor";

import { FromInsertStmtContext } from "./HiveSqlParser";
import { FromSelectStmtContext } from "./HiveSqlParser";
import { InsertStmtContext } from "./HiveSqlParser";
import { SelectStmtContext } from "./HiveSqlParser";
import { ProgramContext } from "./HiveSqlParser";
import { StatementContext } from "./HiveSqlParser";
import { ExplainStatementContext } from "./HiveSqlParser";
Expand Down Expand Up @@ -210,7 +214,6 @@ import { AtomSelectStatementContext } from "./HiveSqlParser";
import { SelectStatementContext } from "./HiveSqlParser";
import { SetOpSelectStatementContext } from "./HiveSqlParser";
import { SelectStatementWithCTEContext } from "./HiveSqlParser";
import { BodyContext } from "./HiveSqlParser";
import { InsertClauseContext } from "./HiveSqlParser";
import { DestinationContext } from "./HiveSqlParser";
import { LimitClauseContext } from "./HiveSqlParser";
Expand Down Expand Up @@ -534,6 +537,38 @@ import { DropMappingStatementContext } from "./HiveSqlParser";
* operations with no return type.
*/
export interface HiveSqlParserVisitor<Result> extends ParseTreeVisitor<Result> {
/**
* Visit a parse tree produced by the `fromInsertStmt`
* labeled alternative in `HiveSqlParser.singleFromStatement`.
* @param ctx the parse tree
* @return the visitor result
*/
visitFromInsertStmt?: (ctx: FromInsertStmtContext) => Result;

/**
* Visit a parse tree produced by the `fromSelectStmt`
* labeled alternative in `HiveSqlParser.singleFromStatement`.
* @param ctx the parse tree
* @return the visitor result
*/
visitFromSelectStmt?: (ctx: FromSelectStmtContext) => Result;

/**
* Visit a parse tree produced by the `insertStmt`
* labeled alternative in `HiveSqlParser.regularBody`.
* @param ctx the parse tree
* @return the visitor result
*/
visitInsertStmt?: (ctx: InsertStmtContext) => Result;

/**
* Visit a parse tree produced by the `selectStmt`
* labeled alternative in `HiveSqlParser.regularBody`.
* @param ctx the parse tree
* @return the visitor result
*/
visitSelectStmt?: (ctx: SelectStmtContext) => Result;

/**
* Visit a parse tree produced by `HiveSqlParser.program`.
* @param ctx the parse tree
Expand Down Expand Up @@ -1983,13 +2018,6 @@ export interface HiveSqlParserVisitor<Result> extends ParseTreeVisitor<Result> {
*/
visitSelectStatementWithCTE?: (ctx: SelectStatementWithCTEContext) => Result;

/**
* Visit a parse tree produced by `HiveSqlParser.body`.
* @param ctx the parse tree
* @return the visitor result
*/
visitBody?: (ctx: BodyContext) => Result;

/**
* Visit a parse tree produced by `HiveSqlParser.insertClause`.
* @param ctx the parse tree
Expand Down
Loading

0 comments on commit 952727d

Please sign in to comment.