[GitHub] spark pull request #18292: [SPARK-21083][SQL] Do not remove correct column s...

2017-07-08 Thread wzhfy
Github user wzhfy commented on a diff in the pull request:

https://github.com/apache/spark/pull/18292#discussion_r126276259
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala
 ---
@@ -40,10 +39,10 @@ case class AnalyzeTableCommand(
 }
 val newTotalSize = CommandUtils.calculateTotalSize(sessionState, 
tableMeta)
 
-val oldTotalSize = 
tableMeta.stats.map(_.sizeInBytes.toLong).getOrElse(0L)
+val oldTotalSize = 
tableMeta.stats.map(_.sizeInBytes.toLong).getOrElse(-1L)
 val oldRowCount = 
tableMeta.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L)
 var newStats: Option[CatalogStatistics] = None
-if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+if (newTotalSize >= 0 && newTotalSize != oldTotalSize) {
--- End diff --

OK. Let me change this pr description to fix this bug. I'll also backport 
it to previous release.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #18292: [SPARK-21083][SQL] Do not remove correct column s...

2017-07-08 Thread wzhfy
Github user wzhfy commented on a diff in the pull request:

https://github.com/apache/spark/pull/18292#discussion_r126276240
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeColumnCommand.scala
 ---
@@ -42,17 +42,20 @@ case class AnalyzeColumnCommand(
 if (tableMeta.tableType == CatalogTableType.VIEW) {
   throw new AnalysisException("ANALYZE TABLE is not supported on 
views.")
 }
-val sizeInBytes = CommandUtils.calculateTotalSize(sessionState, 
tableMeta)
 
+val newSize = CommandUtils.calculateTotalSize(sessionState, tableMeta)
 // Compute stats for each column
-val (rowCount, newColStats) = computeColumnStats(sparkSession, 
tableIdentWithDB, columnNames)
+val (newRowCount, colStats) = computeColumnStats(sparkSession, 
tableIdentWithDB, columnNames)
+
+// Because we will invalidate or update stats when table is changed, 
if column stats exist,
+// they should be correct. Hence, we can combine previous column stats 
and the newly collected
+// column stats.
+val oldColStats = tableMeta.stats.map(_.colStats).getOrElse(Map.empty)
+val newColStats = oldColStats ++ colStats
 
 // We also update table-level stats in order to keep them consistent 
with column-level stats.
 val statistics = CatalogStatistics(
-  sizeInBytes = sizeInBytes,
-  rowCount = Some(rowCount),
-  // Newly computed column stats should override the existing ones.
-  colStats = tableMeta.stats.map(_.colStats).getOrElse(Map.empty) ++ 
newColStats)
--- End diff --

uh...let me revert it. It's been a month and I forget the original code...


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #18292: [SPARK-21083][SQL] Do not remove correct column s...

2017-07-07 Thread gatorsmile
Github user gatorsmile commented on a diff in the pull request:

https://github.com/apache/spark/pull/18292#discussion_r126275492
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala
 ---
@@ -40,10 +39,10 @@ case class AnalyzeTableCommand(
 }
 val newTotalSize = CommandUtils.calculateTotalSize(sessionState, 
tableMeta)
 
-val oldTotalSize = 
tableMeta.stats.map(_.sizeInBytes.toLong).getOrElse(0L)
+val oldTotalSize = 
tableMeta.stats.map(_.sizeInBytes.toLong).getOrElse(-1L)
 val oldRowCount = 
tableMeta.stats.flatMap(_.rowCount.map(_.toLong)).getOrElse(-1L)
 var newStats: Option[CatalogStatistics] = None
-if (newTotalSize > 0 && newTotalSize != oldTotalSize) {
+if (newTotalSize >= 0 && newTotalSize != oldTotalSize) {
--- End diff --

This is a bug we should fix and backport it to the previous releases


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #18292: [SPARK-21083][SQL] Do not remove correct column s...

2017-07-07 Thread gatorsmile
Github user gatorsmile commented on a diff in the pull request:

https://github.com/apache/spark/pull/18292#discussion_r126275485
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeColumnCommand.scala
 ---
@@ -42,17 +42,20 @@ case class AnalyzeColumnCommand(
 if (tableMeta.tableType == CatalogTableType.VIEW) {
   throw new AnalysisException("ANALYZE TABLE is not supported on 
views.")
 }
-val sizeInBytes = CommandUtils.calculateTotalSize(sessionState, 
tableMeta)
 
+val newSize = CommandUtils.calculateTotalSize(sessionState, tableMeta)
 // Compute stats for each column
-val (rowCount, newColStats) = computeColumnStats(sparkSession, 
tableIdentWithDB, columnNames)
+val (newRowCount, colStats) = computeColumnStats(sparkSession, 
tableIdentWithDB, columnNames)
+
+// Because we will invalidate or update stats when table is changed, 
if column stats exist,
+// they should be correct. Hence, we can combine previous column stats 
and the newly collected
+// column stats.
+val oldColStats = tableMeta.stats.map(_.colStats).getOrElse(Map.empty)
+val newColStats = oldColStats ++ colStats
 
 // We also update table-level stats in order to keep them consistent 
with column-level stats.
 val statistics = CatalogStatistics(
-  sizeInBytes = sizeInBytes,
-  rowCount = Some(rowCount),
-  // Newly computed column stats should override the existing ones.
-  colStats = tableMeta.stats.map(_.colStats).getOrElse(Map.empty) ++ 
newColStats)
--- End diff --

Yes. I did not find any semantics difference. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #18292: [SPARK-21083][SQL] Do not remove correct column s...

2017-07-07 Thread cloud-fan
Github user cloud-fan commented on a diff in the pull request:

https://github.com/apache/spark/pull/18292#discussion_r126274515
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeColumnCommand.scala
 ---
@@ -42,17 +42,20 @@ case class AnalyzeColumnCommand(
 if (tableMeta.tableType == CatalogTableType.VIEW) {
   throw new AnalysisException("ANALYZE TABLE is not supported on 
views.")
 }
-val sizeInBytes = CommandUtils.calculateTotalSize(sessionState, 
tableMeta)
 
+val newSize = CommandUtils.calculateTotalSize(sessionState, tableMeta)
 // Compute stats for each column
-val (rowCount, newColStats) = computeColumnStats(sparkSession, 
tableIdentWithDB, columnNames)
+val (newRowCount, colStats) = computeColumnStats(sparkSession, 
tableIdentWithDB, columnNames)
+
+// Because we will invalidate or update stats when table is changed, 
if column stats exist,
+// they should be correct. Hence, we can combine previous column stats 
and the newly collected
+// column stats.
+val oldColStats = tableMeta.stats.map(_.colStats).getOrElse(Map.empty)
+val newColStats = oldColStats ++ colStats
 
 // We also update table-level stats in order to keep them consistent 
with column-level stats.
 val statistics = CatalogStatistics(
-  sizeInBytes = sizeInBytes,
-  rowCount = Some(rowCount),
-  // Newly computed column stats should override the existing ones.
-  colStats = tableMeta.stats.map(_.colStats).getOrElse(Map.empty) ++ 
newColStats)
--- End diff --

seems we already did it?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org