<artifactId>flink-sql_1.14</artifactId><version>1.0</version><name>flink-sql_1.14</name><!-- FIXME change it tothe project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target><flink.version>1.14.0</flink.version><scala.version>2.11</scala.version><hive.version>2.1.1-cdh6.1.1</hive.version><hadoop.version>3.0.0-cdh6.1.1</hadoop.version></properties><repositories><repository><id>cloudera</id><url>https://repository.cloudera.com/artifactory/cloudera-repos/</url></repository><!--<repository>--><!--<id>spring-plugin</id>--><!--<url>https://repo.spring.io/plugins-release/</url>--><!--</repository>--></repositories><dependencies><dependency><groupId>commons-cli</groupId><artifactId>commons-cli</artifactId><version>1.4</version></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-table-api-java-bridge_2.11</artifactId><version>1.14.0</version><scope>provided</scope></dependency><!--FlinkDependency--><dependency><groupId>org.apache.flink</groupId><artifactId>flink-connector-hive_2.11</artifactId><version>1.14.0</version><scope>provided</scope></dependency><dependency><groupId>org.apache.flink</groupId><artifactId>flink-table-api-java-bridge_2.11</artifactId><version>1.14.0</version><scope>provided</scope></dependency><!--HiveDependency--><dependency><groupId>org.apache.hive</groupId><artifactId>hive-exec</artifactId><version>${hive.version}</version><exclusions><exclusion><artifactId>calcite-avatica</artifactId><groupId>org.apache.calcite</groupId></exclusion><exclusion><artifactId>calcite-core</artifactId><groupId>org.apache.calcite</groupId></exclusion><exclusion><artifactId>calcite-linq4j</artifactId><groupId>org.apache.calcite</groupId></exclusion></exclusions><!--<scope>provided</scope>--></dependency><dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>${hadoop.version}</version><exclusions><exclusion><artifactId>commons-math3</artifactId><groupId>org.apache.commons</groupId></exclusion></exclusions><!--<scope>provided</scope>--></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency></dependencies><build><plugins><!--<plugin>--><!--<groupId>net.alchim31.maven</groupId>--><!--<artifactId>scala-maven-plugin</artifactId>--><!--<version>3.4.6</version>--><!--</plugin>--><plugin><groupId>net.alchim31.maven</groupId><artifactId>scala-maven-plugin</artifactId><version>3.2.0</version><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><configuration><scalaCompatVersion>${scala.version}</scalaCompatVersion><scalaVersion>${scala.version}</scalaVersion></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.2</version><configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>3.1.0</version><configuration><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration><executions><execution><id>assemble-all</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build>
code
importorg.apache.flink.table.api.{EnvironmentSettings,SqlDialect,TableEnvironment,TableResult}importorg.apache.flink.table.catalog.hive.HiveCatalogimportorg.apache.flink.types.Rowimportorg.apache.flink.util.CloseableIterator/**
* @Author: GW00234399
* @Description: sth todo
*/
object TestSelectextendsLogging{
def main(args:Array[String]):Unit={
val settings:EnvironmentSettings=EnvironmentSettings.newInstance().useBlinkPlanner().build()
val tEnv =TableEnvironment.create(settings)
val name ="hc"
val defaultDS ="gdc"
val hiveCD:String="/dirpath"
val hiveCatalog =newHiveCatalog(name, defaultDS, hiveCD)
tEnv.registerCatalog("hc",hiveCatalog)
tEnv.useCatalog("hc")
tEnv.getConfig.setSqlDialect(SqlDialect.HIVE)
val sql ="""
|select * from test.student
|""".stripMargin
val result:TableResult= tEnv.executeSql(sql)
result.print()
val value:CloseableIterator[Row]= result.collect()while(value.hasNext){
log.info("row: "+ value.next().toString)}}}