tablesΒΆ

tables returns a SparkDataFrame containing names of tables in the given database. The DataFrame returned will consist of 2 columns, tableName and isTemporary.

Syntax:

  • tables(databaseName = NULL)

Parameters:

  • databaseName: Optional, Name of database

Output:

  • SparkR DataFrame
# Create a database as an example
sql("CREATE DATABASE testDB")

# Create SparkR DataFrame using the faithful dataset from R
df <- createDataFrame(faithful)

# Save df as temporary table in database testDB
registerTempTable(df, "tempTable")
# View tables in database testDB
collect(tables("testDB"))
# tables() will display a full list of existing tables if no database name is specified
collect(tables())
# tables() returns the same results as sql's SHOW TABLES command
head(sql("SHOW TABLES"))
# Drop Database testDB
head(sql("DROP DATABASE testDB"))