0
무작위로 내 데이터의 하위 집합을 선택한 다음 200 개의 항목으로 제한하려고합니다. 그러나 sample()
함수를 사용한 후에 중복 행이 생기고 그 이유를 알 수 없습니다. 나를 보여 드리죠.Spark - 데이터를 복제하는 sample() 함수?
DataFrame df= sqlContext.sql("SELECT * " +
" FROM temptable" +
" WHERE conditions");
DataFrame df1 = df.select(df.col("col1"))
.where(df.col("col1").isNotNull())
.distinct()
.orderBy(df.col("col1"));
df.show();
System.out.println(df.count());
지금까지 모든 것이 정상입니다. 출력 :
+-----------+
|col1 |
+-----------+
| 10016|
| 10022|
| 100281|
| 10032|
| 100427|
| 100445|
| 10049|
| 10070|
| 10076|
| 10079|
| 10081|
| 10082|
| 100884|
| 10092|
| 10099|
| 10102|
| 10103|
| 101039|
| 101134|
| 101187|
+-----------+
only showing top 20 rows
10512
중복이없는 10512 개의 레코드가 있습니다. 그리고!
+-----------+
|col1 |
+-----------+
| 10022|
| 100445|
| 100445|
| 10049|
| 10079|
| 10079|
| 10081|
| 10081|
| 10082|
| 10092|
| 10102|
| 10102|
| 101039|
| 101134|
| 101134|
| 101134|
| 101345|
| 101345|
| 10140|
| 10141|
+-----------+
only showing top 20 rows
200
사람이 말해 왜 수 :
df = df.sample(true, 0.5).limit(200);
df.show();
System.out.println(users.count());
이 중복 전체 200 개 행을 반환? 이것은 나를 미치게 만든다. 고맙습니다!