spark数据集:表数据与创建它的视图的数据不完全相同

u2nhd7ah  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(615)

我的代码与此完全相似。这里只更改了变量和表名。键入时请忽略任何语法错误。原始代码编译成功。
------代码------

Dataset<Row> test = sqlContext.sql("select * from test_table");

test.createOrReplaceTempView("temp_view_test");

sqlContext.sql("drop table if exist new_table");
sqlContext.sql("create table new_table as select * from temp_view_test");

//Code to print counts

//count if dataset
System.out.println("test count:"+test.count());

//count of temp view
Dataset<Row> tempViewTestData = sqlContext.sql("select * from temp_view_test");
System.out.println("temp view count: "+tempViewTestData.count());

//count of newly created table
Dataset<Row> newTableData = sqlContext.sql("select * from new_table");
System.out.println("New Table count: "+newTableData .count());

-----输出----
试验count:9422720 temp 视图计数:9422720新表计数:9520364
-----问题-----
我的问题是为什么新表的计数和临时视图的计数不同。我该怎么做才能使这两个数字相同。

sq1bmfud

sq1bmfud1#

最后我找到了解决办法。这是因为数据集中有日语字符。如果出现类似的问题,可以考虑这一点。

相关问题