[Plugin] Support zookeeper for native

This commit is contained in:
qianmoQ 2023-02-07 21:51:26 +08:00
parent 8ae62bf93a
commit ee31d8a5fd
30 changed files with 1978 additions and 1 deletions

View File

@ -108,6 +108,9 @@ Here are some of the major database solutions that are supported:
</a>&nbsp;
<a href="https://ydb.tech/" target="_blank">
<img src="assets/plugin/ydb.png" alt="YDB" height="50" />
</a>&nbsp;
<a href="https://zookeeper.apache.org/" target="_blank">
<img src="assets/plugin/zookeeper.png" alt="Zookeeper" height="50" />
</a>
</p>

BIN
assets/plugin/zookeeper.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

View File

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!--
This file contains some false positive bugs detected by findbugs. Their
false positive nature has been analyzed individually and they have been
put here to instruct findbugs it must ignore them.
-->
<FindBugsFilter>
<Match>
<Package name="io.edurt.datacap.plugin.natived.zookeeper.sql" />
</Match>
</FindBugsFilter>

View File

@ -15,5 +15,6 @@
<modules>
<module>redis</module>
<module>zookeeper</module>
</modules>
</project>

View File

@ -62,4 +62,4 @@
</plugin>
</plugins>
</build>
</project>
</project>

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>datacap-plugin-native</artifactId>
<groupId>io.edurt.datacap.plugin.natived</groupId>
<version>1.5.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>datacap-plugin-native-zookeeper</artifactId>
<name>DataCap plugin for native (Zookeeper)</name>
<properties>
<antlr4.version>4.9.3</antlr4.version>
<zookeeper.version>0.11</zookeeper.version>
<plugin.name>native-zookeeper</plugin.name>
<antlr4.dir>${project.build.directory}/generated-sources/antlr4</antlr4.dir>
</properties>
<dependencies>
<dependency>
<groupId>io.edurt.datacap</groupId>
<artifactId>datacap-spi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.edurt.datacap.common</groupId>
<artifactId>datacap-common</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${antlr4.version}</version>
</dependency>
<dependency>
<groupId>com.101tec</groupId>
<artifactId>zkclient</artifactId>
<version>${zookeeper.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly-plugin.version}</version>
<configuration>
<finalName>${plugin.name}</finalName>
<descriptors>
<descriptor>../../../configure/assembly/assembly-plugin.xml</descriptor>
</descriptors>
<outputDirectory>../../../dist/plugins/${plugin.name}</outputDirectory>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr4.version}</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
<configuration>
<arguments>
<argument>-package</argument>
<argument>io.edurt.datacap.plugin.natived.zookeeper.sql</argument>
<argument>-o</argument>
<argument>${antlr4.dir}/io/edurt/datacap/plugin/natived/zookeeper/sql</argument>
</arguments>
<sourceDirectory>${basedir}/src/main/antlr4/ZookeeperSql.g4</sourceDirectory>
<listener>true</listener>
<visitor>true</visitor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,32 @@
grammar ZookeeperSql;
singleStatement : statement EOF ;
statement : 'SELECT' selectElements fromClause ;
fromClause : 'FROM' qualifiedName;
selectElements : ID|'*' ;
ID : [a-zA-Z]+ ;
WS : [ \r\n\t]+ -> skip ;
QUOTED_IDENTIFIER
: '"' ( ~'"' | '""' )* '"'
;
BACKQUOTED_IDENTIFIER
: '`' ( ~'`' | '``' )* '`'
;
qualifiedName
: identifier ('.' identifier)*
;
identifier
: IDENTIFIER
| QUOTED_IDENTIFIER #quotedIdentifier
| BACKQUOTED_IDENTIFIER #backQuotedIdentifier
| DIGIT_IDENTIFIER #digitIdentifier
;

View File

@ -0,0 +1,101 @@
package io.edurt.datacap.plugin.natived.zookeeper;
import com.google.common.base.Preconditions;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.edurt.datacap.plugin.natived.zookeeper.sql.ZookeeperCaseInsensitiveStream;
import io.edurt.datacap.plugin.natived.zookeeper.sql.ZookeeperSql;
import io.edurt.datacap.plugin.natived.zookeeper.sql.ZookeeperSqlLexer;
import io.edurt.datacap.plugin.natived.zookeeper.sql.ZookeeperSqlParser;
import io.edurt.datacap.plugin.natived.zookeeper.sql.ZookeeperSqlVisitor;
import io.edurt.datacap.spi.adapter.NativeAdapter;
import io.edurt.datacap.spi.model.Configure;
import io.edurt.datacap.spi.model.Response;
import io.edurt.datacap.spi.model.Time;
import lombok.extern.slf4j.Slf4j;
import org.I0Itec.zkclient.ZkClient;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.tree.ParseTree;
import org.apache.commons.lang3.ObjectUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@Slf4j
@SuppressFBWarnings(value = {"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "REC_CATCH_EXCEPTION"},
justification = "I prefer to suppress these FindBugs warnings")
public class ZookeeperAdapter
extends NativeAdapter
{
protected ZookeeperConnection zookeeperConnection;
public ZookeeperAdapter(ZookeeperConnection zookeeperConnection)
{
super(zookeeperConnection);
this.zookeeperConnection = zookeeperConnection;
}
@Override
public Response handlerExecute(String content)
{
Time processorTime = new Time();
processorTime.setStart(new Date().getTime());
Response response = this.zookeeperConnection.getResponse();
Configure configure = this.zookeeperConnection.getConfigure();
if (response.getIsConnected()) {
List<String> headers = new ArrayList<>();
List<String> types = new ArrayList<>();
List<Object> columns = new ArrayList<>();
try {
CharStream stream = CharStreams.fromString(content);
ZookeeperSqlLexer lexer = new ZookeeperSqlLexer(new ZookeeperCaseInsensitiveStream(stream));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ZookeeperSqlParser parser = new ZookeeperSqlParser(tokens);
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
parser.removeErrorListeners();
ParseTree tree = null;
try {
tree = parser.singleStatement();
}
catch (Exception ex) {
Preconditions.checkArgument(false, "Not support this sql");
}
ZookeeperSqlVisitor simpleSqlTreeVisitor = new ZookeeperSqlVisitor();
if (ObjectUtils.isNotEmpty(tree)) {
ZookeeperSql node = simpleSqlTreeVisitor.visit(tree);
Preconditions.checkArgument(node.isSupport(), String.format("Not support type <%s>", node.getToken()));
ZkClient client = this.zookeeperConnection.getClient();
headers.add(node.getColumns().get(0));
types.add("String");
if (node.getTable().equalsIgnoreCase("all")) {
node.setTable("");
}
client.getChildren("/" + node.getTable().replace(".", "/"))
.forEach(column -> columns.add(handlerFormatter(configure.getFormat(), headers, Collections.singletonList(column))));
response.setIsSuccessful(Boolean.TRUE);
}
}
catch (Exception ex) {
log.error("Execute content failed content {} exception ", content, ex);
response.setIsSuccessful(Boolean.FALSE);
response.setMessage(ex.getMessage());
}
finally {
response.setHeaders(headers);
response.setTypes(types);
response.setColumns(columns);
}
}
processorTime.setEnd(new Date().getTime());
response.setProcessor(processorTime);
return response;
}
}

View File

@ -0,0 +1,57 @@
package io.edurt.datacap.plugin.natived.zookeeper;
import io.edurt.datacap.spi.connection.Connection;
import io.edurt.datacap.spi.model.Configure;
import io.edurt.datacap.spi.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.I0Itec.zkclient.ZkClient;
@Slf4j
public class ZookeeperConnection
extends Connection
{
private Configure configure;
private Response response;
private ZkClient client;
public ZookeeperConnection(Configure configure, Response response)
{
super(configure, response);
}
@Override
protected String formatJdbcUrl()
{
return null;
}
@Override
protected java.sql.Connection openConnection()
{
try {
this.configure = getConfigure();
this.response = getResponse();
log.info("Connection url {}", formatJdbcUrl());
this.client = new ZkClient(this.configure.getHost(), 60000, 5000);
response.setIsConnected(Boolean.TRUE);
}
catch (Exception ex) {
log.error("Connection failed ", ex);
response.setIsConnected(Boolean.FALSE);
response.setMessage(ex.getMessage());
}
return null;
}
@Override
public void destroy()
{
this.client.close();
log.info("Connection close successful");
}
public ZkClient getClient()
{
return client;
}
}

View File

@ -0,0 +1,80 @@
package io.edurt.datacap.plugin.natived.zookeeper;
import io.edurt.datacap.spi.Plugin;
import io.edurt.datacap.spi.PluginType;
import io.edurt.datacap.spi.adapter.Adapter;
import io.edurt.datacap.spi.connection.JdbcConfigure;
import io.edurt.datacap.spi.model.Configure;
import io.edurt.datacap.spi.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.ObjectUtils;
@Slf4j
public class ZookeeperPlugin
implements Plugin
{
private Configure configure;
private ZookeeperConnection connection;
private Response response;
@Override
public String validator()
{
return "SELECT * FROM all";
}
@Override
public String name()
{
return "Zookeeper";
}
@Override
public String description()
{
return "Integrate Zookeeper data sources";
}
@Override
public PluginType type()
{
return PluginType.NATIVE;
}
@Override
public void connect(Configure configure)
{
try {
this.response = new Response();
this.configure = new JdbcConfigure();
BeanUtils.copyProperties(this.configure, configure);
this.connection = new ZookeeperConnection(this.configure, this.response);
}
catch (Exception ex) {
this.response.setIsConnected(Boolean.FALSE);
this.response.setMessage(ex.getMessage());
}
}
@Override
public Response execute(String content)
{
if (ObjectUtils.isNotEmpty(this.connection)) {
log.info("Execute zookeeper plugin logic started");
this.response = this.connection.getResponse();
Adapter processor = new ZookeeperAdapter(this.connection);
this.response = processor.handlerExecute(content);
log.info("Execute zookeeper plugin logic end");
}
return this.response;
}
@Override
public void destroy()
{
if (ObjectUtils.isNotEmpty(this.connection)) {
this.connection.destroy();
}
}
}

View File

@ -0,0 +1,38 @@
package io.edurt.datacap.plugin.natived.zookeeper;
import com.google.inject.multibindings.Multibinder;
import io.edurt.datacap.spi.AbstractPluginModule;
import io.edurt.datacap.spi.Plugin;
import io.edurt.datacap.spi.PluginModule;
import io.edurt.datacap.spi.PluginType;
public class ZookeeperPluginModule
extends AbstractPluginModule
implements PluginModule
{
@Override
public String getName()
{
return "Zookeeper";
}
@Override
public PluginType getType()
{
return PluginType.NATIVE;
}
@Override
public AbstractPluginModule get()
{
return this;
}
protected void configure()
{
Multibinder<String> module = Multibinder.newSetBinder(this.binder(), String.class);
module.addBinding().toInstance(this.getClass().getSimpleName());
Multibinder<Plugin> plugin = Multibinder.newSetBinder(this.binder(), Plugin.class);
plugin.addBinding().to(ZookeeperPlugin.class);
}
}

View File

@ -0,0 +1,78 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.IntStream;
import org.antlr.v4.runtime.misc.Interval;
public class ZookeeperCaseInsensitiveStream
implements CharStream
{
private final CharStream stream;
public ZookeeperCaseInsensitiveStream(CharStream stream)
{
this.stream = stream;
}
@Override
public String getText(Interval interval)
{
return stream.getText(interval);
}
@Override
public void consume()
{
stream.consume();
}
@Override
public int LA(int i)
{
int result = stream.LA(i);
switch (result) {
case 0:
case IntStream.EOF:
return result;
default:
return Character.toUpperCase(result);
}
}
@Override
public int mark()
{
return stream.mark();
}
@Override
public void release(int marker)
{
stream.release(marker);
}
@Override
public int index()
{
return stream.index();
}
@Override
public void seek(int index)
{
stream.seek(index);
}
@Override
public int size()
{
return stream.size();
}
@Override
public String getSourceName()
{
return stream.getSourceName();
}
}

View File

@ -0,0 +1,37 @@
token literal names:
null
'SELECT'
'FROM'
'*'
'.'
null
null
null
null
null
null
token symbolic names:
null
null
null
null
null
ID
WS
QUOTED_IDENTIFIER
BACKQUOTED_IDENTIFIER
IDENTIFIER
DIGIT_IDENTIFIER
rule names:
singleStatement
statement
fromClause
selectElements
qualifiedName
identifier
atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 12, 37, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 7, 6, 30, 10, 6, 12, 6, 14, 6, 33, 11, 6, 3, 7, 3, 7, 3, 7, 2, 2, 8, 2, 4, 6, 8, 10, 12, 2, 4, 4, 2, 5, 5, 7, 7, 3, 2, 9, 12, 2, 31, 2, 14, 3, 2, 2, 2, 4, 17, 3, 2, 2, 2, 6, 21, 3, 2, 2, 2, 8, 24, 3, 2, 2, 2, 10, 26, 3, 2, 2, 2, 12, 34, 3, 2, 2, 2, 14, 15, 5, 4, 3, 2, 15, 16, 7, 2, 2, 3, 16, 3, 3, 2, 2, 2, 17, 18, 7, 3, 2, 2, 18, 19, 5, 8, 5, 2, 19, 20, 5, 6, 4, 2, 20, 5, 3, 2, 2, 2, 21, 22, 7, 4, 2, 2, 22, 23, 5, 10, 6, 2, 23, 7, 3, 2, 2, 2, 24, 25, 9, 2, 2, 2, 25, 9, 3, 2, 2, 2, 26, 31, 5, 12, 7, 2, 27, 28, 7, 6, 2, 2, 28, 30, 5, 12, 7, 2, 29, 27, 3, 2, 2, 2, 30, 33, 3, 2, 2, 2, 31, 29, 3, 2, 2, 2, 31, 32, 3, 2, 2, 2, 32, 11, 3, 2, 2, 2, 33, 31, 3, 2, 2, 2, 34, 35, 9, 3, 2, 2, 35, 13, 3, 2, 2, 2, 3, 31]

View File

@ -0,0 +1,22 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.ArrayList;
import java.util.List;
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ZookeeperSql
{
private ZookeeperSqlToken token;
private boolean from;
private List<String> columns = new ArrayList<>();
private String table;
private boolean isSupport = false;
}

View File

@ -0,0 +1,14 @@
T__0=1
T__1=2
T__2=3
T__3=4
ID=5
WS=6
QUOTED_IDENTIFIER=7
BACKQUOTED_IDENTIFIER=8
IDENTIFIER=9
DIGIT_IDENTIFIER=10
'SELECT'=1
'FROM'=2
'*'=3
'.'=4

View File

@ -0,0 +1,191 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
// Generated from ZookeeperSql.g4 by ANTLR 4.9.3
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
/**
* This class provides an empty implementation of {@link ZookeeperSqlListener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
public class ZookeeperSqlBaseListener
implements ZookeeperSqlListener
{
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterSingleStatement(ZookeeperSqlParser.SingleStatementContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitSingleStatement(ZookeeperSqlParser.SingleStatementContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterStatement(ZookeeperSqlParser.StatementContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitStatement(ZookeeperSqlParser.StatementContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterFromClause(ZookeeperSqlParser.FromClauseContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitFromClause(ZookeeperSqlParser.FromClauseContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterSelectElements(ZookeeperSqlParser.SelectElementsContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitSelectElements(ZookeeperSqlParser.SelectElementsContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterQualifiedName(ZookeeperSqlParser.QualifiedNameContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitQualifiedName(ZookeeperSqlParser.QualifiedNameContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterUnquotedIdentifier(ZookeeperSqlParser.UnquotedIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitUnquotedIdentifier(ZookeeperSqlParser.UnquotedIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterQuotedIdentifier(ZookeeperSqlParser.QuotedIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitQuotedIdentifier(ZookeeperSqlParser.QuotedIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterBackQuotedIdentifier(ZookeeperSqlParser.BackQuotedIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitBackQuotedIdentifier(ZookeeperSqlParser.BackQuotedIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterDigitIdentifier(ZookeeperSqlParser.DigitIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitDigitIdentifier(ZookeeperSqlParser.DigitIdentifierContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void enterEveryRule(ParserRuleContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void exitEveryRule(ParserRuleContext ctx) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void visitTerminal(TerminalNode node) {}
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override
public void visitErrorNode(ErrorNode node) {}
}

View File

@ -0,0 +1,41 @@
token literal names:
null
'SELECT'
'FROM'
'*'
'.'
null
null
null
null
token symbolic names:
null
null
null
null
null
ID
WS
QUOTED_IDENTIFIER
BACKQUOTED_IDENTIFIER
rule names:
T__0
T__1
T__2
T__3
ID
WS
QUOTED_IDENTIFIER
BACKQUOTED_IDENTIFIER
channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN
mode names:
DEFAULT_MODE
atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 10, 69, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 6, 6, 37, 10, 6, 13, 6, 14, 6, 38, 3, 7, 6, 7, 42, 10, 7, 13, 7, 14, 7, 43, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 7, 8, 52, 10, 8, 12, 8, 14, 8, 55, 11, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 3, 9, 7, 9, 63, 10, 9, 12, 9, 14, 9, 66, 11, 9, 3, 9, 3, 9, 2, 2, 10, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 3, 2, 6, 4, 2, 67, 92, 99, 124, 5, 2, 11, 12, 15, 15, 34, 34, 3, 2, 36, 36, 3, 2, 98, 98, 2, 74, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 3, 19, 3, 2, 2, 2, 5, 26, 3, 2, 2, 2, 7, 31, 3, 2, 2, 2, 9, 33, 3, 2, 2, 2, 11, 36, 3, 2, 2, 2, 13, 41, 3, 2, 2, 2, 15, 47, 3, 2, 2, 2, 17, 58, 3, 2, 2, 2, 19, 20, 7, 85, 2, 2, 20, 21, 7, 71, 2, 2, 21, 22, 7, 78, 2, 2, 22, 23, 7, 71, 2, 2, 23, 24, 7, 69, 2, 2, 24, 25, 7, 86, 2, 2, 25, 4, 3, 2, 2, 2, 26, 27, 7, 72, 2, 2, 27, 28, 7, 84, 2, 2, 28, 29, 7, 81, 2, 2, 29, 30, 7, 79, 2, 2, 30, 6, 3, 2, 2, 2, 31, 32, 7, 44, 2, 2, 32, 8, 3, 2, 2, 2, 33, 34, 7, 48, 2, 2, 34, 10, 3, 2, 2, 2, 35, 37, 9, 2, 2, 2, 36, 35, 3, 2, 2, 2, 37, 38, 3, 2, 2, 2, 38, 36, 3, 2, 2, 2, 38, 39, 3, 2, 2, 2, 39, 12, 3, 2, 2, 2, 40, 42, 9, 3, 2, 2, 41, 40, 3, 2, 2, 2, 42, 43, 3, 2, 2, 2, 43, 41, 3, 2, 2, 2, 43, 44, 3, 2, 2, 2, 44, 45, 3, 2, 2, 2, 45, 46, 8, 7, 2, 2, 46, 14, 3, 2, 2, 2, 47, 53, 7, 36, 2, 2, 48, 52, 10, 4, 2, 2, 49, 50, 7, 36, 2, 2, 50, 52, 7, 36, 2, 2, 51, 48, 3, 2, 2, 2, 51, 49, 3, 2, 2, 2, 52, 55, 3, 2, 2, 2, 53, 51, 3, 2, 2, 2, 53, 54, 3, 2, 2, 2, 54, 56, 3, 2, 2, 2, 55, 53, 3, 2, 2, 2, 56, 57, 7, 36, 2, 2, 57, 16, 3, 2, 2, 2, 58, 64, 7, 98, 2, 2, 59, 63, 10, 5, 2, 2, 60, 61, 7, 98, 2, 2, 61, 63, 7, 98, 2, 2, 62, 59, 3, 2, 2, 2, 62, 60, 3, 2, 2, 2, 63, 66, 3, 2, 2, 2, 64, 62, 3, 2, 2, 2, 64, 65, 3, 2, 2, 2, 65, 67, 3, 2, 2, 2, 66, 64, 3, 2, 2, 2, 67, 68, 7, 98, 2, 2, 68, 18, 3, 2, 2, 2, 9, 2, 38, 43, 51, 53, 62, 64, 3, 8, 2, 2]

View File

@ -0,0 +1,144 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
// Generated from ZookeeperSql.g4 by ANTLR 4.9.3
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.RuntimeMetaData;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class ZookeeperSqlLexer
extends Lexer
{
static {
RuntimeMetaData.checkVersion("4.9.3", RuntimeMetaData.VERSION);
}
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, ID = 5, WS = 6;
public static String[] channelNames = {
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
};
public static String[] modeNames = {
"DEFAULT_MODE"
};
private static String[] makeRuleNames()
{
return new String[] {
"T__0", "T__1", "T__2", "T__3", "ID", "WS"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames()
{
return new String[] {
null, "'SELECT'", "'FROM'", "'*'", "'.'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames()
{
return new String[] {
null, null, null, null, null, "ID", "WS"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames()
{
return tokenNames;
}
@Override
public Vocabulary getVocabulary()
{
return VOCABULARY;
}
public ZookeeperSqlLexer(CharStream input)
{
super(input);
_interp = new LexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
@Override
public String getGrammarFileName() {return "ZookeeperSql.g4";}
@Override
public String[] getRuleNames() {return ruleNames;}
@Override
public String getSerializedATN() {return _serializedATN;}
@Override
public String[] getChannelNames() {return channelNames;}
@Override
public String[] getModeNames() {return modeNames;}
@Override
public ATN getATN() {return _ATN;}
public static final String _serializedATN =
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\b+\b\1\4\2\t\2\4" +
"\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2\3\2\3\2\3\2\3\2\3\2\3\2\3\3" +
"\3\3\3\3\3\3\3\3\3\4\3\4\3\5\3\5\3\6\6\6!\n\6\r\6\16\6\"\3\7\6\7&\n\7" +
"\r\7\16\7\'\3\7\3\7\2\2\b\3\3\5\4\7\5\t\6\13\7\r\b\3\2\4\4\2C\\c|\5\2" +
"\13\f\17\17\"\"\2,\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13" +
"\3\2\2\2\2\r\3\2\2\2\3\17\3\2\2\2\5\26\3\2\2\2\7\33\3\2\2\2\t\35\3\2\2" +
"\2\13 \3\2\2\2\r%\3\2\2\2\17\20\7U\2\2\20\21\7G\2\2\21\22\7N\2\2\22\23" +
"\7G\2\2\23\24\7E\2\2\24\25\7V\2\2\25\4\3\2\2\2\26\27\7H\2\2\27\30\7T\2" +
"\2\30\31\7Q\2\2\31\32\7O\2\2\32\6\3\2\2\2\33\34\7,\2\2\34\b\3\2\2\2\35" +
"\36\7\60\2\2\36\n\3\2\2\2\37!\t\2\2\2 \37\3\2\2\2!\"\3\2\2\2\" \3\2\2" +
"\2\"#\3\2\2\2#\f\3\2\2\2$&\t\3\2\2%$\3\2\2\2&\'\3\2\2\2\'%\3\2\2\2\'(" +
"\3\2\2\2()\3\2\2\2)*\b\7\2\2*\16\3\2\2\2\5\2\"\'\3\b\2\2";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,12 @@
T__0=1
T__1=2
T__2=3
T__3=4
ID=5
WS=6
QUOTED_IDENTIFIER=7
BACKQUOTED_IDENTIFIER=8
'SELECT'=1
'FROM'=2
'*'=3
'.'=4

View File

@ -0,0 +1,146 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
// Generated from ZookeeperSql.g4 by ANTLR 4.9.3
import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
* {@link ZookeeperSqlParser}.
*/
public interface ZookeeperSqlListener
extends ParseTreeListener
{
/**
* Enter a parse tree produced by {@link ZookeeperSqlParser#singleStatement}.
*
* @param ctx the parse tree
*/
void enterSingleStatement(ZookeeperSqlParser.SingleStatementContext ctx);
/**
* Exit a parse tree produced by {@link ZookeeperSqlParser#singleStatement}.
*
* @param ctx the parse tree
*/
void exitSingleStatement(ZookeeperSqlParser.SingleStatementContext ctx);
/**
* Enter a parse tree produced by {@link ZookeeperSqlParser#statement}.
*
* @param ctx the parse tree
*/
void enterStatement(ZookeeperSqlParser.StatementContext ctx);
/**
* Exit a parse tree produced by {@link ZookeeperSqlParser#statement}.
*
* @param ctx the parse tree
*/
void exitStatement(ZookeeperSqlParser.StatementContext ctx);
/**
* Enter a parse tree produced by {@link ZookeeperSqlParser#fromClause}.
*
* @param ctx the parse tree
*/
void enterFromClause(ZookeeperSqlParser.FromClauseContext ctx);
/**
* Exit a parse tree produced by {@link ZookeeperSqlParser#fromClause}.
*
* @param ctx the parse tree
*/
void exitFromClause(ZookeeperSqlParser.FromClauseContext ctx);
/**
* Enter a parse tree produced by {@link ZookeeperSqlParser#selectElements}.
*
* @param ctx the parse tree
*/
void enterSelectElements(ZookeeperSqlParser.SelectElementsContext ctx);
/**
* Exit a parse tree produced by {@link ZookeeperSqlParser#selectElements}.
*
* @param ctx the parse tree
*/
void exitSelectElements(ZookeeperSqlParser.SelectElementsContext ctx);
/**
* Enter a parse tree produced by {@link ZookeeperSqlParser#qualifiedName}.
*
* @param ctx the parse tree
*/
void enterQualifiedName(ZookeeperSqlParser.QualifiedNameContext ctx);
/**
* Exit a parse tree produced by {@link ZookeeperSqlParser#qualifiedName}.
*
* @param ctx the parse tree
*/
void exitQualifiedName(ZookeeperSqlParser.QualifiedNameContext ctx);
/**
* Enter a parse tree produced by the {@code unquotedIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void enterUnquotedIdentifier(ZookeeperSqlParser.UnquotedIdentifierContext ctx);
/**
* Exit a parse tree produced by the {@code unquotedIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void exitUnquotedIdentifier(ZookeeperSqlParser.UnquotedIdentifierContext ctx);
/**
* Enter a parse tree produced by the {@code quotedIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void enterQuotedIdentifier(ZookeeperSqlParser.QuotedIdentifierContext ctx);
/**
* Exit a parse tree produced by the {@code quotedIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void exitQuotedIdentifier(ZookeeperSqlParser.QuotedIdentifierContext ctx);
/**
* Enter a parse tree produced by the {@code backQuotedIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void enterBackQuotedIdentifier(ZookeeperSqlParser.BackQuotedIdentifierContext ctx);
/**
* Exit a parse tree produced by the {@code backQuotedIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void exitBackQuotedIdentifier(ZookeeperSqlParser.BackQuotedIdentifierContext ctx);
/**
* Enter a parse tree produced by the {@code digitIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void enterDigitIdentifier(ZookeeperSqlParser.DigitIdentifierContext ctx);
/**
* Exit a parse tree produced by the {@code digitIdentifier}
* labeled alternative in {@link ZookeeperSqlParser#identifier}.
*
* @param ctx the parse tree
*/
void exitDigitIdentifier(ZookeeperSqlParser.DigitIdentifierContext ctx);
}

View File

@ -0,0 +1,640 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
// Generated from ZookeeperSql.g4 by ANTLR 4.9.3
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.RuntimeMetaData;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.ParserATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.List;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class ZookeeperSqlParser
extends Parser
{
static {
RuntimeMetaData.checkVersion("4.9.3", RuntimeMetaData.VERSION);
}
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
new PredictionContextCache();
public static final int
T__0 = 1, T__1 = 2, T__2 = 3, T__3 = 4, ID = 5, WS = 6, IDENTIFIER = 7, QUOTED_IDENTIFIER = 8,
BACKQUOTED_IDENTIFIER = 9, DIGIT_IDENTIFIER = 10;
public static final int
RULE_singleStatement = 0, RULE_statement = 1, RULE_fromClause = 2, RULE_selectElements = 3,
RULE_qualifiedName = 4, RULE_identifier = 5;
private static String[] makeRuleNames()
{
return new String[] {
"singleStatement", "statement", "fromClause", "selectElements", "qualifiedName",
"identifier"
};
}
public static final String[] ruleNames = makeRuleNames();
private static String[] makeLiteralNames()
{
return new String[] {
null, "'SELECT'", "'FROM'", "'*'", "'.'"
};
}
private static final String[] _LITERAL_NAMES = makeLiteralNames();
private static String[] makeSymbolicNames()
{
return new String[] {
null, null, null, null, null, "ID", "WS", "IDENTIFIER", "QUOTED_IDENTIFIER",
"BACKQUOTED_IDENTIFIER", "DIGIT_IDENTIFIER"
};
}
private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
/**
* @deprecated Use {@link #VOCABULARY} instead.
*/
@Deprecated
public static final String[] tokenNames;
static {
tokenNames = new String[_SYMBOLIC_NAMES.length];
for (int i = 0; i < tokenNames.length; i++) {
tokenNames[i] = VOCABULARY.getLiteralName(i);
if (tokenNames[i] == null) {
tokenNames[i] = VOCABULARY.getSymbolicName(i);
}
if (tokenNames[i] == null) {
tokenNames[i] = "<INVALID>";
}
}
}
@Override
@Deprecated
public String[] getTokenNames()
{
return tokenNames;
}
@Override
public Vocabulary getVocabulary()
{
return VOCABULARY;
}
@Override
public String getGrammarFileName() {return "ZookeeperSql.g4";}
@Override
public String[] getRuleNames() {return ruleNames;}
@Override
public String getSerializedATN() {return _serializedATN;}
@Override
public ATN getATN() {return _ATN;}
public ZookeeperSqlParser(TokenStream input)
{
super(input);
_interp = new ParserATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
public static class SingleStatementContext
extends ParserRuleContext
{
public StatementContext statement()
{
return getRuleContext(StatementContext.class, 0);
}
public TerminalNode EOF() {return getToken(ZookeeperSqlParser.EOF, 0);}
public SingleStatementContext(ParserRuleContext parent, int invokingState)
{
super(parent, invokingState);
}
@Override
public int getRuleIndex() {return RULE_singleStatement;}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterSingleStatement(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitSingleStatement(this);
}
}
}
public final SingleStatementContext singleStatement()
throws RecognitionException
{
SingleStatementContext _localctx = new SingleStatementContext(_ctx, getState());
enterRule(_localctx, 0, RULE_singleStatement);
try {
enterOuterAlt(_localctx, 1);
{
setState(12);
statement();
setState(13);
match(EOF);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class StatementContext
extends ParserRuleContext
{
public SelectElementsContext selectElements()
{
return getRuleContext(SelectElementsContext.class, 0);
}
public FromClauseContext fromClause()
{
return getRuleContext(FromClauseContext.class, 0);
}
public StatementContext(ParserRuleContext parent, int invokingState)
{
super(parent, invokingState);
}
@Override
public int getRuleIndex() {return RULE_statement;}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterStatement(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitStatement(this);
}
}
}
public final StatementContext statement()
throws RecognitionException
{
StatementContext _localctx = new StatementContext(_ctx, getState());
enterRule(_localctx, 2, RULE_statement);
try {
enterOuterAlt(_localctx, 1);
{
setState(15);
match(T__0);
setState(16);
selectElements();
setState(17);
fromClause();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class FromClauseContext
extends ParserRuleContext
{
public QualifiedNameContext qualifiedName()
{
return getRuleContext(QualifiedNameContext.class, 0);
}
public FromClauseContext(ParserRuleContext parent, int invokingState)
{
super(parent, invokingState);
}
@Override
public int getRuleIndex() {return RULE_fromClause;}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterFromClause(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitFromClause(this);
}
}
}
public final FromClauseContext fromClause()
throws RecognitionException
{
FromClauseContext _localctx = new FromClauseContext(_ctx, getState());
enterRule(_localctx, 4, RULE_fromClause);
try {
enterOuterAlt(_localctx, 1);
{
setState(19);
match(T__1);
setState(20);
qualifiedName();
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class SelectElementsContext
extends ParserRuleContext
{
public TerminalNode ID() {return getToken(ZookeeperSqlParser.ID, 0);}
public SelectElementsContext(ParserRuleContext parent, int invokingState)
{
super(parent, invokingState);
}
@Override
public int getRuleIndex() {return RULE_selectElements;}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterSelectElements(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitSelectElements(this);
}
}
}
public final SelectElementsContext selectElements()
throws RecognitionException
{
SelectElementsContext _localctx = new SelectElementsContext(_ctx, getState());
enterRule(_localctx, 6, RULE_selectElements);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(22);
_la = _input.LA(1);
if (!(_la == T__2 || _la == ID)) {
_errHandler.recoverInline(this);
}
else {
if (_input.LA(1) == Token.EOF) {
matchedEOF = true;
}
_errHandler.reportMatch(this);
consume();
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class QualifiedNameContext
extends ParserRuleContext
{
public List<IdentifierContext> identifier()
{
return getRuleContexts(IdentifierContext.class);
}
public IdentifierContext identifier(int i)
{
return getRuleContext(IdentifierContext.class, i);
}
public QualifiedNameContext(ParserRuleContext parent, int invokingState)
{
super(parent, invokingState);
}
@Override
public int getRuleIndex() {return RULE_qualifiedName;}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterQualifiedName(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitQualifiedName(this);
}
}
}
public final QualifiedNameContext qualifiedName()
throws RecognitionException
{
QualifiedNameContext _localctx = new QualifiedNameContext(_ctx, getState());
enterRule(_localctx, 8, RULE_qualifiedName);
int _la;
try {
enterOuterAlt(_localctx, 1);
{
setState(24);
identifier();
setState(29);
_errHandler.sync(this);
_la = _input.LA(1);
while (_la == T__3) {
{
{
setState(25);
match(T__3);
setState(26);
identifier();
}
}
setState(31);
_errHandler.sync(this);
_la = _input.LA(1);
}
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static class IdentifierContext
extends ParserRuleContext
{
public IdentifierContext(ParserRuleContext parent, int invokingState)
{
super(parent, invokingState);
}
@Override
public int getRuleIndex() {return RULE_identifier;}
public IdentifierContext() {}
public void copyFrom(IdentifierContext ctx)
{
super.copyFrom(ctx);
}
}
public static class BackQuotedIdentifierContext
extends IdentifierContext
{
public TerminalNode BACKQUOTED_IDENTIFIER() {return getToken(ZookeeperSqlParser.BACKQUOTED_IDENTIFIER, 0);}
public BackQuotedIdentifierContext(IdentifierContext ctx) {copyFrom(ctx);}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterBackQuotedIdentifier(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitBackQuotedIdentifier(this);
}
}
}
public static class QuotedIdentifierContext
extends IdentifierContext
{
public TerminalNode QUOTED_IDENTIFIER() {return getToken(ZookeeperSqlParser.QUOTED_IDENTIFIER, 0);}
public QuotedIdentifierContext(IdentifierContext ctx) {copyFrom(ctx);}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterQuotedIdentifier(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitQuotedIdentifier(this);
}
}
}
public static class DigitIdentifierContext
extends IdentifierContext
{
public TerminalNode DIGIT_IDENTIFIER() {return getToken(ZookeeperSqlParser.DIGIT_IDENTIFIER, 0);}
public DigitIdentifierContext(IdentifierContext ctx) {copyFrom(ctx);}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterDigitIdentifier(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitDigitIdentifier(this);
}
}
}
public static class UnquotedIdentifierContext
extends IdentifierContext
{
public TerminalNode IDENTIFIER() {return getToken(ZookeeperSqlParser.IDENTIFIER, 0);}
public UnquotedIdentifierContext(IdentifierContext ctx) {copyFrom(ctx);}
@Override
public void enterRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).enterUnquotedIdentifier(this);
}
}
@Override
public void exitRule(ParseTreeListener listener)
{
if (listener instanceof ZookeeperSqlListener) {
((ZookeeperSqlListener) listener).exitUnquotedIdentifier(this);
}
}
}
public final IdentifierContext identifier()
throws RecognitionException
{
IdentifierContext _localctx = new IdentifierContext(_ctx, getState());
enterRule(_localctx, 10, RULE_identifier);
try {
setState(36);
_errHandler.sync(this);
switch (_input.LA(1)) {
case IDENTIFIER:
_localctx = new UnquotedIdentifierContext(_localctx);
enterOuterAlt(_localctx, 1);
{
setState(32);
match(IDENTIFIER);
}
break;
case QUOTED_IDENTIFIER:
_localctx = new QuotedIdentifierContext(_localctx);
enterOuterAlt(_localctx, 2);
{
setState(33);
match(QUOTED_IDENTIFIER);
}
break;
case BACKQUOTED_IDENTIFIER:
_localctx = new BackQuotedIdentifierContext(_localctx);
enterOuterAlt(_localctx, 3);
{
setState(34);
match(BACKQUOTED_IDENTIFIER);
}
break;
case DIGIT_IDENTIFIER:
_localctx = new DigitIdentifierContext(_localctx);
enterOuterAlt(_localctx, 4);
{
setState(35);
match(DIGIT_IDENTIFIER);
}
break;
default:
throw new NoViableAltException(this);
}
}
catch (RecognitionException re) {
_localctx.exception = re;
_errHandler.reportError(this, re);
_errHandler.recover(this, re);
}
finally {
exitRule();
}
return _localctx;
}
public static final String _serializedATN =
"\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\f)\4\2\t\2\4\3\t" +
"\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2\3\2\3\2\3\3\3\3\3\3\3\3\3\4\3\4" +
"\3\4\3\5\3\5\3\6\3\6\3\6\7\6\36\n\6\f\6\16\6!\13\6\3\7\3\7\3\7\3\7\5\7" +
"\'\n\7\3\7\2\2\b\2\4\6\b\n\f\2\3\4\2\5\5\7\7\2&\2\16\3\2\2\2\4\21\3\2" +
"\2\2\6\25\3\2\2\2\b\30\3\2\2\2\n\32\3\2\2\2\f&\3\2\2\2\16\17\5\4\3\2\17" +
"\20\7\2\2\3\20\3\3\2\2\2\21\22\7\3\2\2\22\23\5\b\5\2\23\24\5\6\4\2\24" +
"\5\3\2\2\2\25\26\7\4\2\2\26\27\5\n\6\2\27\7\3\2\2\2\30\31\t\2\2\2\31\t" +
"\3\2\2\2\32\37\5\f\7\2\33\34\7\6\2\2\34\36\5\f\7\2\35\33\3\2\2\2\36!\3" +
"\2\2\2\37\35\3\2\2\2\37 \3\2\2\2 \13\3\2\2\2!\37\3\2\2\2\"\'\7\t\2\2#" +
"\'\7\n\2\2$\'\7\13\2\2%\'\7\f\2\2&\"\3\2\2\2&#\3\2\2\2&$\3\2\2\2&%\3\2" +
"\2\2\'\r\3\2\2\2\4\37&";
public static final ATN _ATN =
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
static {
_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
}
}
}

View File

@ -0,0 +1,6 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
public enum ZookeeperSqlToken
{
SELECT
}

View File

@ -0,0 +1,77 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import org.antlr.v4.runtime.tree.RuleNode;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.Arrays;
public class ZookeeperSqlVisitor
implements ParseTreeVisitor<ZookeeperSql>
{
ZookeeperSql configure;
public ZookeeperSqlVisitor()
{
configure = new ZookeeperSql();
}
@Override
public ZookeeperSql visit(ParseTree tree)
{
int childCount = tree.getChildCount();
for (int i = 0; i < childCount; i++) {
ParseTree child = tree.getChild(i);
if (child instanceof ZookeeperSqlParser.StatementContext) {
ZookeeperSqlParser.StatementContext statementContext = (ZookeeperSqlParser.StatementContext) child;
handlerWithStatement(statementContext);
}
}
return configure;
}
private void handlerWithStatement(ZookeeperSqlParser.StatementContext statementContext)
{
int childCount = statementContext.getChildCount();
int i = 0;
for (; i < childCount; i++) {
ParseTree child = statementContext.getChild(i);
if (child instanceof ZookeeperSqlParser.SelectElementsContext) {
configure.setColumns(Arrays.asList(child.getText()));
}
else if (child instanceof ZookeeperSqlParser.FromClauseContext) {
configure.setTable(child.getChild(1).getText());
configure.setFrom(true);
}
else if (child instanceof TerminalNode) {
if (child.getText().equalsIgnoreCase("SELECT")) {
configure.setSupport(true);
configure.setToken(ZookeeperSqlToken.SELECT);
}
}
}
}
@Override
public ZookeeperSql visitChildren(RuleNode node)
{
// TODO Auto-generated method stub
return null;
}
@Override
public ZookeeperSql visitTerminal(TerminalNode node)
{
// TODO Auto-generated method stub
return null;
}
@Override
public ZookeeperSql visitErrorNode(ErrorNode node)
{
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1 @@
io.edurt.datacap.plugin.natived.zookeeper.ZookeeperPluginModule

View File

@ -0,0 +1,30 @@
package io.edurt.datacap.plugin.natived.zookeeper;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import io.edurt.datacap.spi.Plugin;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Set;
public class ZookeeperPluginModuleTest
{
private Injector injector;
@Before
public void before()
{
this.injector = Guice.createInjector(new ZookeeperPluginModule());
}
@Test
public void test()
{
Set<Plugin> plugins = injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}));
Assert.assertTrue(plugins.size() > 0);
}
}

View File

@ -0,0 +1,43 @@
package io.edurt.datacap.plugin.natived.zookeeper;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import io.edurt.datacap.spi.Plugin;
import io.edurt.datacap.spi.model.Configure;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.Optional;
import java.util.Set;
public class ZookeeperPluginTest
{
private Injector injector;
private Configure configure;
@Before
public void before()
{
injector = Guice.createInjector(new ZookeeperPluginModule());
configure = new Configure();
configure.setHost("localhost:2181");
}
@Test
public void test()
{
Set<Plugin> plugins = injector.getInstance(Key.get(new TypeLiteral<Set<Plugin>>() {}));
Optional<Plugin> pluginOptional = plugins.stream()
.filter(v -> v.name().equalsIgnoreCase("Zookeeper"))
.findFirst();
if (pluginOptional.isPresent()) {
Plugin plugin = pluginOptional.get();
plugin.connect(configure);
Assert.assertNotNull(plugin.execute(plugin.validator()).getConnection());
plugin.destroy();
}
}
}

View File

@ -0,0 +1,53 @@
package io.edurt.datacap.plugin.natived.zookeeper.sql;
import com.google.common.base.Preconditions;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.tree.ParseTree;
import org.apache.commons.lang3.ObjectUtils;
import org.junit.Assert;
import org.junit.Test;
public class ZookeeperSqlParserTest
{
public ZookeeperSql getConfigure(String sql)
{
CharStream stream = CharStreams.fromString(sql);
ZookeeperSqlLexer lexer = new ZookeeperSqlLexer(new ZookeeperCaseInsensitiveStream(stream));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ZookeeperSqlParser parser = new ZookeeperSqlParser(tokens);
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
parser.removeErrorListeners();
ParseTree tree = null;
try {
tree = parser.singleStatement();
}
catch (Exception ex) {
Preconditions.checkArgument(false, "Not support this sql");
}
ZookeeperSqlVisitor simpleSqlTreeVisitor = new ZookeeperSqlVisitor();
if (ObjectUtils.isNotEmpty(tree)) {
ZookeeperSql configure = simpleSqlTreeVisitor.visit(tree);
return configure;
}
return null;
}
@Test
public void testSelect()
{
String sql = "SELECT * FROM test.dd.dd";
ZookeeperSql configure = getConfigure(sql);
Assert.assertEquals(configure.getToken(), ZookeeperSqlToken.SELECT);
Assert.assertTrue(configure.getColumns().size() > 0);
Assert.assertNotNull(configure.getTable());
sql = "Select * FROM test.dd.dd";
configure = getConfigure(sql);
Assert.assertNotNull(configure.getTable());
}
}

View File

@ -259,6 +259,11 @@
<artifactId>datacap-plugin-jdbc-ydb</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.edurt.datacap.plugin.natived</groupId>
<artifactId>datacap-plugin-native-zookeeper</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,19 @@
{
"name": "Zookeeper",
"supportTime": "2023-02-07",
"configures": [
{
"field": "name",
"type": "String",
"required": true,
"message": "name is a required field, please be sure to enter"
},
{
"field": "host",
"type": "String",
"required": true,
"value": "127.0.0.1:2181",
"message": "host is a required field, please be sure to enter"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB