pyspark.sql.HiveContext#
- class pyspark.sql.HiveContext(sparkContext, sparkSession=None, jhiveContext=None)[source]#
A variant of Spark SQL that integrates with data stored in Hive.
Configuration for Hive is read from
hive-site.xmlon the classpath. It supports running both SQL and HiveQL commands.Deprecated since version 2.0.0: Use SparkSession.builder.enableHiveSupport().getOrCreate().
- Parameters:
- sparkContext
SparkContext The SparkContext to wrap.
- jhiveContextoptional
An optional JVM Scala HiveContext. If set, we do not instantiate a new
HiveContextin the JVM, instead we make all calls to this object. This is only for internal use.
- sparkContext
Methods
cacheTable(tableName)Caches the specified table in-memory.
clearCache()Removes all cached tables from the in-memory cache.
createDataFrame(data[, schema, ...])Creates a
DataFramefrom anRDD, a list, apandas.DataFrame, or apyarrow.Table.createExternalTable(tableName[, path, ...])Creates an external table based on the dataset in a data source.
dropTempTable(tableName)Remove the temporary table from catalog.
getConf(key[, defaultValue])Returns the value of Spark SQL configuration property for the given key.
getOrCreate([sc])Get the existing SQLContext or create a new one with given SparkContext.
newSession()Returns a new SQLContext as new session, that has separate SQLConf, registered temporary views and UDFs, but shared SparkContext and table cache.
range(start[, end, step, numPartitions])Create a
DataFramewith singlepyspark.sql.types.LongTypecolumn namedid, containing elements in a range fromstarttoend(exclusive) with step valuestep.refreshTable(tableName)Invalidate and refresh all the cached metadata of the given table.
registerDataFrameAsTable(df, tableName)Registers the given
DataFrameas a temporary table in the catalog.registerFunction(name, f[, returnType])An alias for
spark.udf.register().registerJavaFunction(name, javaClassName[, ...])An alias for
spark.udf.registerJavaFunction().setConf(key, value)Sets the given Spark SQL configuration property.
sql(sqlQuery)Returns a
DataFramerepresenting the result of the given query.table(tableName)Returns the specified table or view as a
DataFrame.tableNames([dbName])Returns a list of names of tables in the database
dbName.tables([dbName])Returns a
DataFramecontaining names of tables in the given database.uncacheTable(tableName)Removes the specified table from the in-memory cache.
Attributes
readReturns a
DataFrameReaderthat can be used to read data in as aDataFrame.readStreamReturns a
DataStreamReaderthat can be used to read data streams as a streamingDataFrame.streamsReturns a
StreamingQueryManagerthat allows managing all theStreamingQueryStreamingQueries active on this context.udfReturns a
UDFRegistrationfor UDF registration.udtfReturns a
UDTFRegistrationfor UDTF registration.