forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#11 from XuMingmin/sql-rowrecord
merge all changes for dsl_sql_init
- Loading branch information
Showing
54 changed files
with
3,431 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- | ||
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. | ||
--> | ||
|
||
# Beam DSLs | ||
|
||
*It's working in progress...* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!-- | ||
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. | ||
--> | ||
|
||
# Beam SQL | ||
|
||
Beam SQL provides a new interface, to execute a SQL query as a Beam pipeline. | ||
|
||
*It's working in progress...* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?xml version="1.0"?> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.beam</groupId> | ||
<artifactId>beam-dsls-parent</artifactId> | ||
<version>0.7.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>beam-dsls-sql</artifactId> | ||
<name>Apache Beam :: DSLs :: SQL</name> | ||
<description>Beam SQL provides a new interface to generate a Beam pipeline from SQL statement</description> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<timestamp>${maven.build.timestamp}</timestamp> | ||
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format> | ||
<calcite-version>1.11.0</calcite-version> | ||
</properties> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
</resource> | ||
</resources> | ||
|
||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
<configuration> | ||
<!-- Set testSourceDirectory in order to exclude generated-test-sources --> | ||
<testSourceDirectory>${project.basedir}/src/test/</testSourceDirectory> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<argLine>-da</argLine> <!-- disable assert in Calcite converter validation --> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>bundle-and-repackage</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<shadeTestJar>true</shadeTestJar> | ||
<artifactSet> | ||
<includes> | ||
<include>com.google.guava:guava</include> | ||
</includes> | ||
</artifactSet> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<!-- Coverage analysis for unit tests. --> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.calcite</groupId> | ||
<artifactId>calcite-core</artifactId> | ||
<version>${calcite-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.beam</groupId> | ||
<artifactId>beam-sdks-java-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.beam</groupId> | ||
<artifactId>beam-runners-direct-java</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.beam</groupId> | ||
<artifactId>beam-sdks-java-io-kafka</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-expression</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-jdk14</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.calcite</groupId> | ||
<artifactId>calcite-linq4j</artifactId> | ||
<version>${calcite-version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
102 changes: 102 additions & 0 deletions
102
dsls/sql/src/main/java/org/beam/dsls/sql/example/BeamSqlExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.beam.dsls.sql.example; | ||
|
||
import java.io.Serializable; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
import org.apache.calcite.rel.type.RelProtoDataType; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
import org.beam.dsls.sql.planner.BeamSqlRunner; | ||
import org.beam.dsls.sql.schema.BaseBeamTable; | ||
import org.beam.dsls.sql.schema.kafka.BeamKafkaCSVTable; | ||
|
||
/** | ||
* This is one quick example.<br/> | ||
* Before start, follow https://kafka.apache.org/quickstart to setup a Kafka | ||
* cluster locally, and run below commands to create required Kafka topics: | ||
* <pre> | ||
* <code> | ||
* bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 \ | ||
* --partitions 1 --topic orders | ||
* bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 \ | ||
* --partitions 1 --topic sub_orders | ||
* </code> | ||
* </pre> | ||
* After run the application, produce several test records: | ||
* <pre> | ||
* <code> | ||
* bin/kafka-console-producer.sh --broker-list localhost:9092 --topic orders | ||
* invalid,record | ||
* 123445,0,100,3413423 | ||
* 234123,3,232,3451231234 | ||
* 234234,0,5,1234123 | ||
* 345234,0,345234.345,3423 | ||
* </code> | ||
* </pre> | ||
* Meanwhile, open another console to see the output: | ||
* <pre> | ||
* <code> | ||
* bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic sub_orders | ||
* **Expected : | ||
* 123445,0,100.0 | ||
* 345234,0,345234.345 | ||
* </code> | ||
* </pre> | ||
*/ | ||
public class BeamSqlExample implements Serializable { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = 3673487843555563904L; | ||
|
||
public static void main(String[] args) throws Exception { | ||
BeamSqlRunner runner = new BeamSqlRunner(); | ||
runner.addTable("ORDER_DETAILS", getTable("127.0.0.1:9092", "orders")); | ||
runner.addTable("SUB_ORDER", getTable("127.0.0.1:9092", "sub_orders")); | ||
|
||
// case 2: insert into <table>(<fields>) select STREAM <fields> from | ||
// <table> from <clause> | ||
String sql = "INSERT INTO SUB_ORDER(order_id, site_id, price) " + "SELECT " | ||
+ " order_id, site_id, price " + "FROM ORDER_DETAILS " + "WHERE SITE_ID = 0 and price > 20"; | ||
|
||
runner.explainQuery(sql); | ||
runner.submitQuery(sql); | ||
} | ||
|
||
public static BaseBeamTable getTable(String bootstrapServer, String topic) { | ||
final RelProtoDataType protoRowType = new RelProtoDataType() { | ||
@Override | ||
public RelDataType apply(RelDataTypeFactory a0) { | ||
return a0.builder().add("order_id", SqlTypeName.BIGINT).add("site_id", SqlTypeName.INTEGER) | ||
.add("price", SqlTypeName.DOUBLE).add("order_time", SqlTypeName.TIMESTAMP).build(); | ||
} | ||
}; | ||
|
||
Map<String, Object> consumerPara = new HashMap<String, Object>(); | ||
consumerPara.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "latest"); | ||
|
||
return new BeamKafkaCSVTable(protoRowType, bootstrapServer, Arrays.asList(topic)) | ||
.updateConsumerProperties(consumerPara); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
dsls/sql/src/main/java/org/beam/dsls/sql/example/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* examples on how to use BeamSQL. | ||
* | ||
*/ | ||
package org.beam.dsls.sql.example; |
45 changes: 45 additions & 0 deletions
45
dsls/sql/src/main/java/org/beam/dsls/sql/interpreter/BeamSQLExpressionExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.beam.dsls.sql.interpreter; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
import org.beam.dsls.sql.schema.BeamSQLRow; | ||
|
||
/** | ||
* {@code BeamSQLExpressionExecutor} fills the gap between relational | ||
* expressions in Calcite SQL and executable code. | ||
* | ||
*/ | ||
public interface BeamSQLExpressionExecutor extends Serializable { | ||
|
||
/** | ||
* invoked before data processing. | ||
*/ | ||
void prepare(); | ||
|
||
/** | ||
* apply transformation to input record {@link BeamSQLRow}. | ||
* | ||
* @param inputRecord | ||
* @return | ||
*/ | ||
List<Object> execute(BeamSQLRow inputRecord); | ||
|
||
void close(); | ||
} |
Oops, something went wrong.