flink table 计算具有相同条目的行数
flink table count rows with the same entry
我有一个 table 的列中有不同的条目(但我不知道所有条目)
table:
column1 | column2
x1 | y1
x1 | y2
x2 | y2
x3 | y1
x3 | y2
现在我想要一个列表或字典,其中第一列的所有条目都是计数的:
dict = (x1:2, x2:1, x3:2)
我试过了:
table = env.readCsvFile(tablepath).as('column1, 'column2)
var content = table.select('column1)
content.count()
我尝试使用字数统计示例 link,但它需要一个字符串数组作为输入?!所以
Wordcount(content) or Wordcount(content.toString())
无效。
如果你想对 column1
中的每个值进行计数,你需要按 column1
分组并计数:
table = env.readCsvFile(tablepath).as('column1, 'column2)
var content = table.groupBy('column1').select('column1.count)
WordCount
的输入指定输入和输出文件或您的数据(它需要两个字符串---或 none,用于使用内存中的示例数据并将结果打印到stdout
)。参数,不是要处理的数据。
我有一个 table 的列中有不同的条目(但我不知道所有条目)
table:
column1 | column2
x1 | y1
x1 | y2
x2 | y2
x3 | y1
x3 | y2
现在我想要一个列表或字典,其中第一列的所有条目都是计数的:
dict = (x1:2, x2:1, x3:2)
我试过了:
table = env.readCsvFile(tablepath).as('column1, 'column2)
var content = table.select('column1)
content.count()
我尝试使用字数统计示例 link,但它需要一个字符串数组作为输入?!所以
Wordcount(content) or Wordcount(content.toString())
无效。
如果你想对 column1
中的每个值进行计数,你需要按 column1
分组并计数:
table = env.readCsvFile(tablepath).as('column1, 'column2)
var content = table.groupBy('column1').select('column1.count)
WordCount
的输入指定输入和输出文件或您的数据(它需要两个字符串---或 none,用于使用内存中的示例数据并将结果打印到stdout
)。参数,不是要处理的数据。