Skip to content

Commit

Permalink
[FLINK-4562] [table] Move table examples into a dedicated module in f…
Browse files Browse the repository at this point in the history
…link-examples.

This closes apache#2460.
  • Loading branch information
shijinkui authored and fhueske committed Apr 21, 2017
1 parent 83061ad commit 46a950d
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 14 deletions.
1 change: 1 addition & 0 deletions flink-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ under the License.
<excludes>
<exclude>org.apache.flink:flink-examples-batch</exclude>
<exclude>org.apache.flink:flink-examples-streaming</exclude>
<exclude>org.apache.flink:flink-examples-table</exclude>
<exclude>org.apache.flink:flink-python</exclude>
<exclude>org.slf4j:slf4j-log4j12</exclude>
<exclude>log4j:log4j</exclude>
Expand Down
108 changes: 108 additions & 0 deletions flink-examples/flink-examples-table/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
https://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.
-->
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://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.apache.flink</groupId>
<artifactId>flink-examples_2.10</artifactId>
<version>1.3-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<name>flink-examples-table</name>
<artifactId>flink-examples-table_2.10</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table_2.10</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>flink-table-examples_2.10</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadeTestJar>false</shadeTestJar>
<shadedArtifactAttached>false</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>TableExamples</finalName>
<outputFile>flink-examples-table-with-dependencies.jar</outputFile>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>org.codehaus.commons.compiler.properties</include>
<include>org/codehaus/janino/**</include>
<include>org/codehaus/commons/**</include>
<include>org/apache/calcite/**</include>
<include>org/apache/flink/table/**</include>
<include>org/apache/flink/shaded/calcite/com/google/common/**</include>
<include>org/apache/flink/shaded/calcite/org/eigenbase/util/property/**</include>
</includes>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
package org.apache.flink.table.examples.java;

import org.apache.flink.table.api.Table;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.table.api.java.BatchTableEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.java.BatchTableEnvironment;

/**
* Simple example that shows how the Batch SQL API is used in Java.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
*/
package org.apache.flink.table.examples.java;

import org.apache.flink.table.api.Table;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.table.api.java.BatchTableEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.api.java.BatchTableEnvironment;

/**
* Simple example for demonstrating the use of the Table API for a Word Count in Java.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
package org.apache.flink.table.examples.scala

import org.apache.flink.api.scala._
import org.apache.flink.table.api.scala._
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}
import org.apache.flink.table.api.TableEnvironment
import org.apache.flink.table.api.scala._

/**
* Simple example for demonstrating the use of SQL on a Stream Table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
package org.apache.flink.table.examples.scala

import org.apache.flink.api.scala._
import org.apache.flink.table.api.scala._
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}
import org.apache.flink.table.api.TableEnvironment
import org.apache.flink.table.api.scala._

/**
* Simple example for demonstrating the use of Table API on a Stream Table.
*
* This example shows how to:
* - Convert DataStreams to Tables
* - Apply union, select, and filter operations
*
*/
object StreamTableExample {

Expand Down
1 change: 1 addition & 0 deletions flink-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ under the License.
<modules>
<module>flink-examples-batch</module>
<module>flink-examples-streaming</module>
<module>flink-examples-table</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.apache.flink.table.api.scala._
import org.apache.flink.api.scala.util.CollectionDataSets
import org.apache.flink.types.Row
import org.apache.flink.table.api.TableEnvironment
import org.apache.flink.table.examples.scala.WordCountTable.{WC => MyWC}
import org.apache.flink.test.util.TestBaseUtils
import org.junit._
import org.junit.runner.RunWith
Expand Down Expand Up @@ -156,17 +155,17 @@ class AggregationsITCase(
val tEnv = TableEnvironment.getTableEnvironment(env, config)

val input = env.fromElements(
MyWC("hello", 1),
MyWC("hello", 1),
MyWC("ciao", 1),
MyWC("hola", 1),
MyWC("hola", 1))
WC("hello", 1),
WC("hello", 1),
WC("ciao", 1),
WC("hola", 1),
WC("hola", 1))
val expr = input.toTable(tEnv)
val result = expr
.groupBy('word)
.select('word, 'frequency.sum as 'frequency)
.filter('frequency === 2)
.toDataSet[MyWC]
.toDataSet[WC]

val mappedResult = result.map(w => (w.word, w.frequency * 10)).collect()
val expected = "(hello,20)\n" + "(hola,20)"
Expand Down Expand Up @@ -339,4 +338,6 @@ class AggregationsITCase(
val results = t.toDataSet[Row].collect()
TestBaseUtils.compareResultAsText(results.asJava, expected)
}

case class WC(word: String, frequency: Long)
}

0 comments on commit 46a950d

Please sign in to comment.