You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flink.apache.org by Cody Innowhere <e....@gmail.com> on 2016/06/02 11:56:13 UTC

How to run table api in 1.1-SNAPSHOT

Hi guys,
I'm trying to run Table-API in master trunk using the sql/registerDataSet
APIs in TableEnvironment class.

According to the doc in table.md, after registering a table, I should be
able to use a sql query on the tabelEnv, so I made a slight change in
WordCountTable.scala by simply adding two lines:

---------------------------------------------------------
object WordCountTable {

  case class WC(word: String, count: Int)

  def main(args: Array[String]): Unit = {

    // set up execution environment
    val env = ExecutionEnvironment.getExecutionEnvironment
    val tEnv = TableEnvironment.getTableEnvironment(env)

    val input = env.fromElements(WC("hello", 1), WC("hello", 2), WC("ciao",
3))
    val expr = input.toTable(tEnv)

    // *************** added lines ***************
    tEnv.registerDataSet("WC", input, 'word, 'count)
    val result1 = tEnv.sql("SELECT word FROM WC ")

    val result = expr
      .groupBy('word)
      .select('word, 'count.sum as 'count)
      .toDataSet[WC]

    result.print()
  }
}

As you can see current query sql is "SELECT word FROM WC" and it works.
But when I change query sql to :
"SELECT word, count FROM WC" it does not work with the exception:
"Exception in thread "main"
org.apache.calcite.sql.parser.SqlParseException: Encountered "count FROM"
at line 1, column 13.
Was expecting one of:
  ...
  ..."

Do I miss something?

BTW., I read the doc at
https://docs.google.com/document/d/1TLayJNOTBle_-m1rQfgA6Ouj1oYsfqRjPcp1h2TVqdI/,
I suppose Task2 has been finished already, right? And is somebody working
on Task3? Do we have a time map for SQL on Flink?

Thanks~

Re: How to run table api in 1.1-SNAPSHOT

Posted by Cody Innowhere <e....@gmail.com>.
Yes, it's the name "count" that caused the problem, thanks for your
explanation.
Still, the word-count example uses an embarrassing field name in table API
case that I would naturally use "select word, count" in SQL while
forgetting the keyword...

On Mon, Jun 6, 2016 at 4:31 PM, Ufuk Celebi <uc...@apache.org> wrote:

> On Mon, Jun 6, 2016 at 8:35 AM, Vasiliki Kalavri
> <va...@gmail.com> wrote:
> > column "count"? Can you try renaming it to "myCount" or something else? I
>
> For String expressions, it's also possible to escape it via "...as
> `count`...", but I'm not sure how this translates to the DSL
> expressions. Any ideas, Fabian or Aljoscha?
>
> – Ufuk
>

Re: How to run table api in 1.1-SNAPSHOT

Posted by Ufuk Celebi <uc...@apache.org>.
On Mon, Jun 6, 2016 at 8:35 AM, Vasiliki Kalavri
<va...@gmail.com> wrote:
> column "count"? Can you try renaming it to "myCount" or something else? I

For String expressions, it's also possible to escape it via "...as
`count`...", but I'm not sure how this translates to the DSL
expressions. Any ideas, Fabian or Aljoscha?

– Ufuk

Re: How to run table api in 1.1-SNAPSHOT

Posted by Vasiliki Kalavri <va...@gmail.com>.
Hi Cody,

could it be you're getting this error because you've named a SQL table
column "count"? Can you try renaming it to "myCount" or something else? I
think the parser recognizes the aggregate function instead :)

Cheers,
-V.
On Jun 2, 2016 1:56 PM, "Cody Innowhere" <e....@gmail.com> wrote:

> Hi guys,
> I'm trying to run Table-API in master trunk using the sql/registerDataSet
> APIs in TableEnvironment class.
>
> According to the doc in table.md, after registering a table, I should be
> able to use a sql query on the tabelEnv, so I made a slight change in
> WordCountTable.scala by simply adding two lines:
>
> ---------------------------------------------------------
> object WordCountTable {
>
>   case class WC(word: String, count: Int)
>
>   def main(args: Array[String]): Unit = {
>
>     // set up execution environment
>     val env = ExecutionEnvironment.getExecutionEnvironment
>     val tEnv = TableEnvironment.getTableEnvironment(env)
>
>     val input = env.fromElements(WC("hello", 1), WC("hello", 2), WC("ciao",
> 3))
>     val expr = input.toTable(tEnv)
>
>     // *************** added lines ***************
>     tEnv.registerDataSet("WC", input, 'word, 'count)
>     val result1 = tEnv.sql("SELECT word FROM WC ")
>
>     val result = expr
>       .groupBy('word)
>       .select('word, 'count.sum as 'count)
>       .toDataSet[WC]
>
>     result.print()
>   }
> }
>
> As you can see current query sql is "SELECT word FROM WC" and it works.
> But when I change query sql to :
> "SELECT word, count FROM WC" it does not work with the exception:
> "Exception in thread "main"
> org.apache.calcite.sql.parser.SqlParseException: Encountered "count FROM"
> at line 1, column 13.
> Was expecting one of:
>   ...
>   ..."
>
> Do I miss something?
>
> BTW., I read the doc at
>
> https://docs.google.com/document/d/1TLayJNOTBle_-m1rQfgA6Ouj1oYsfqRjPcp1h2TVqdI/
> ,
> I suppose Task2 has been finished already, right? And is somebody working
> on Task3? Do we have a time map for SQL on Flink?
>
> Thanks~
>