Search code examples
pythonhivepysparkapache-spark-sqlhivecontext

how to get an integer value while querying a count query through DataFrame?


I am writing this code to get the integer value of count in specified table:

sc = SparkContext("local", "spar")
hive_context = HiveContext(sc)
hive_context.sql("use zs_trainings_trainings_db")
df = hive_context.sql("select count(*) from ldg_sales")

Solution

  • Either:

    hive_context.table("sales").count
    

    or

    hive_context.sql("select count(*) from ldg_sales").first()[0]