<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to get the total number of records in a delta table from the stats, without querying it? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-get-the-total-number-of-records-in-a-delta-table-from-the/m-p/20441#M13794</link>
    <description />
    <pubDate>Thu, 24 Jun 2021 18:26:12 GMT</pubDate>
    <dc:creator>brickster_2018</dc:creator>
    <dc:date>2021-06-24T18:26:12Z</dc:date>
    <item>
      <title>How to get the total number of records in a delta table from the stats, without querying it?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-get-the-total-number-of-records-in-a-delta-table-from-the/m-p/20441#M13794</link>
      <description />
      <pubDate>Thu, 24 Jun 2021 18:26:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-get-the-total-number-of-records-in-a-delta-table-from-the/m-p/20441#M13794</guid>
      <dc:creator>brickster_2018</dc:creator>
      <dc:date>2021-06-24T18:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the total number of records in a delta table from the stats, without querying it?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-get-the-total-number-of-records-in-a-delta-table-from-the/m-p/20442#M13795</link>
      <description>&lt;P&gt;The below code can be used to get the number of records in a Delta table without querying it&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%scala
import com.databricks.sql.transaction.tahoe.DeltaLog
import org.apache.hadoop.fs.Path
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.functions._
&amp;nbsp;
val deltaTablePath = "location of the table"
&amp;nbsp;
def getRecordCount(deltaTablePath: String): Any = {
  val snapshot = DeltaLog.forTable(spark, new Path(deltaTablePath)).update()
  val statsSchema = snapshot.statsSchema
  var files = snapshot.allFiles.withColumn("stats", from_json($"stats", statsSchema))
  val dfWithNumRecords = files.select($"path", $"stats.numRecords".as("numRecords"))
  val totalCount = dfWithNumRecords.select(sum($"numRecords")).first().get(0)
  return totalCount
 }
println(getRecordCount(deltaTablePath))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 18:27:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-get-the-total-number-of-records-in-a-delta-table-from-the/m-p/20442#M13795</guid>
      <dc:creator>brickster_2018</dc:creator>
      <dc:date>2021-06-24T18:27:27Z</dc:date>
    </item>
  </channel>
</rss>

