我知道德鲁伊有scala / php客户端,但是我使用java并且我不想直接通过HTTP查询德鲁伊数据库,是否有可用的java德鲁伊客户端?
答案 0 :(得分:2)
这是一个简单的 Spring Boot Java应用程序,它使用 Avatica JDBC驱动程序查询 Druid 数据,并打印查询的第一行。 / p>
假设Druid在本地运行,并且您已经在表名“ druid_table ”中包含数据,该表的列为 sourceIP
FlinkDruidApplication.java
@SpringBootApplication
public class FlinkDruidApplication {
public static void main(String[] args) {
SpringApplication.run(FlinkDruidApplication.class, args);
Logger log = LoggerFactory.getLogger("FlinkDruidApplication");
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Row> dbData =
env.createInput(
JDBCInputFormat
.buildJDBCInputFormat()
.setDrivername("org.apache.calcite.avatica.remote.Driver")
.setDBUrl("jdbc:avatica:remote:url=http://localhost:8082/druid/v2/sql/avatica/")
.setUsername("null")
.setPassword("null")
.setQuery(
"SELECT sourceIP FROM druid_table"
)
.setRowTypeInfo((RowTypeInfo) Types.ROW(Types.STRING))
.finish()
);
try {
log.info("Printing first IP :: {} " + dbData.collect().iterator().next());
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.shashank</groupId>
<artifactId>FlinkDruid</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FlinkDruid</name>
<description>Flink Druid Connection</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-core -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-core</artifactId>
<version>1.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-streaming-java -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.12</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-java -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>1.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-clients -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.12</artifactId>
<version>1.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-jdbc -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-jdbc_2.12</artifactId>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.calcite.avatica/avatica-core -->
<dependency>
<groupId>org.apache.calcite.avatica</groupId>
<artifactId>avatica-core</artifactId>
<version>1.15.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
答案 1 :(得分:0)
最简单的事情可能是Scrapy uses。
答案 2 :(得分:0)
请结帐DruidDry。这是一个用于查询druid的基于Java的实用程序库。
Druid dry提供了使用Java API编写查询json和查询到代理节点的支持。当前,它不支持少数复杂的JSON,也不支持提取规范。但是,它确实支持大多数常见操作,例如选择,扫描,分组依据等。
您的项目需要在Java 8或更高版本上运行,才能与Druid Dry客户一起使用。
答案 3 :(得分:0)
您还可以使用druidry(基于Java的实用程序库)