@@ -529,7 +529,7 @@ case class Person(name: String, age: Int)
529529
530530// Create an RDD of Person objects and register it as a table.
531531val people = sc.textFile("examples/src/main/resources/people.txt").map(_ .split(",")).map(p => Person(p(0), p(1).trim.toInt)).toDF()
532- people.registerTempTable ("people")
532+ people.createOrReplaceTempView ("people")
533533
534534// SQL statements can be run by using the sql methods provided by sqlContext.
535535val teenagers = sqlContext.sql("SELECT name, age FROM people WHERE age >= 13 AND age <= 19")
@@ -605,7 +605,7 @@ JavaRDD<Person> people = sc.textFile("examples/src/main/resources/people.txt").m
605605
606606// Apply a schema to an RDD of JavaBeans and register it as a table.
607607DataFrame schemaPeople = sqlContext.createDataFrame(people, Person.class);
608- schemaPeople.registerTempTable ("people");
608+ schemaPeople.createOrReplaceTempView ("people");
609609
610610// SQL can be run over RDDs that have been registered as tables.
611611DataFrame teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19")
@@ -643,7 +643,7 @@ people = parts.map(lambda p: Row(name=p[0], age=int(p[1])))
643643
644644# Infer the schema, and register the DataFrame as a table.
645645schemaPeople = sqlContext.createDataFrame(people)
646- schemaPeople.registerTempTable ("people")
646+ schemaPeople.createOrReplaceTempView ("people")
647647
648648# SQL can be run over DataFrames that have been registered as a table.
649649teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19")
@@ -703,8 +703,8 @@ val rowRDD = people.map(_.split(",")).map(p => Row(p(0), p(1).trim))
703703// Apply the schema to the RDD.
704704val peopleDataFrame = sqlContext.createDataFrame(rowRDD, schema)
705705
706- // Register the DataFrames as a table .
707- peopleDataFrame.registerTempTable ("people")
706+ // Creates a temporary view using the DataFrame .
707+ peopleDataFrame.createOrReplaceTempView ("people")
708708
709709// SQL statements can be run by using the sql methods provided by sqlContext.
710710val results = sqlContext.sql("SELECT name FROM people")
@@ -771,10 +771,10 @@ JavaRDD<Row> rowRDD = people.map(
771771// Apply the schema to the RDD.
772772DataFrame peopleDataFrame = sqlContext.createDataFrame(rowRDD, schema);
773773
774- // Register the DataFrame as a table .
775- peopleDataFrame.registerTempTable ("people");
774+ // Creates a temporary view using the DataFrame .
775+ peopleDataFrame.createOrReplaceTempView ("people");
776776
777- // SQL can be run over RDDs that have been registered as tables .
777+ // SQL can be run over a temporary view created using DataFrames .
778778DataFrame results = sqlContext.sql("SELECT name FROM people");
779779
780780// The results of SQL queries are DataFrames and support all the normal RDD operations.
@@ -824,8 +824,8 @@ schema = StructType(fields)
824824# Apply the schema to the RDD.
825825schemaPeople = sqlContext.createDataFrame(people, schema)
826826
827- # Register the DataFrame as a table.
828- schemaPeople.registerTempTable ("people")
827+ # Creates a temporary view using the DataFrame
828+ schemaPeople.createOrReplaceTempView ("people")
829829
830830# SQL can be run over DataFrames that have been registered as a table.
831831results = sqlContext.sql("SELECT name FROM people")
@@ -844,7 +844,7 @@ for name in names.collect():
844844# Data Sources
845845
846846Spark SQL supports operating on a variety of data sources through the ` DataFrame ` interface.
847- A DataFrame can be operated on as normal RDDs and can also be registered as a temporary table .
847+ A DataFrame can be operated on as normal RDDs and can also be used to create a temporary view .
848848Registering a DataFrame as a table allows you to run SQL queries over its data. This section
849849describes the general methods for loading and saving data using the Spark Data Sources and then
850850goes into specific options that are available for the built-in data sources.
@@ -1072,8 +1072,8 @@ people.write.parquet("people.parquet")
10721072// The result of loading a Parquet file is also a DataFrame.
10731073val parquetFile = sqlContext.read.parquet("people.parquet")
10741074
1075- //Parquet files can also be registered as tables and then used in SQL statements.
1076- parquetFile.registerTempTable ("parquetFile")
1075+ // Parquet files can also be used to create a temporary view and then used in SQL statements.
1076+ parquetFile.createOrReplaceTempView ("parquetFile")
10771077val teenagers = sqlContext.sql("SELECT name FROM parquetFile WHERE age >= 13 AND age <= 19")
10781078teenagers.map(t => "Name: " + t(0)).collect().foreach(println)
10791079{% endhighlight %}
@@ -1094,8 +1094,8 @@ schemaPeople.write().parquet("people.parquet");
10941094// The result of loading a parquet file is also a DataFrame.
10951095DataFrame parquetFile = sqlContext.read().parquet("people.parquet");
10961096
1097- // Parquet files can also be registered as tables and then used in SQL statements.
1098- parquetFile.registerTempTable ("parquetFile");
1097+ // Parquet files can also be used to create a temporary view and then used in SQL statements.
1098+ parquetFile.createOrReplaceTempView ("parquetFile");
10991099DataFrame teenagers = sqlContext.sql("SELECT name FROM parquetFile WHERE age >= 13 AND age <= 19");
11001100List<String > teenagerNames = teenagers.javaRDD().map(new Function<Row, String>() {
11011101 public String call(Row row) {
@@ -1120,8 +1120,8 @@ schemaPeople.write.parquet("people.parquet")
11201120# The result of loading a parquet file is also a DataFrame.
11211121parquetFile = sqlContext.read.parquet("people.parquet")
11221122
1123- # Parquet files can also be registered as tables and then used in SQL statements.
1124- parquetFile.registerTempTable ("parquetFile");
1123+ # Parquet files can also be used to create a temporary view and then used in SQL statements.
1124+ parquetFile.createOrReplaceTempView ("parquetFile");
11251125teenagers = sqlContext.sql("SELECT name FROM parquetFile WHERE age >= 13 AND age <= 19")
11261126teenNames = teenagers.map(lambda p: "Name: " + p.name)
11271127for teenName in teenNames.collect():
@@ -1144,7 +1144,7 @@ write.parquet(schemaPeople, "people.parquet")
11441144# The result of loading a parquet file is also a DataFrame.
11451145parquetFile <- read.parquet(sqlContext, "people.parquet")
11461146
1147- # Parquet files can also be registered as tables and then used in SQL statements.
1147+ # Parquet files can also be used to create a temporary view and then used in SQL statements.
11481148registerTempTable(parquetFile, "parquetFile")
11491149teenagers <- sql(sqlContext, "SELECT name FROM parquetFile WHERE age >= 13 AND age <= 19")
11501150schema <- structType(structField("name", "string"))
@@ -1506,8 +1506,8 @@ people.printSchema()
15061506// |-- age: long (nullable = true)
15071507// |-- name: string (nullable = true)
15081508
1509- // Register this DataFrame as a table.
1510- people.registerTempTable ("people")
1509+ // Creates a temporary view using the DataFrame
1510+ people.createOrReplaceTempView ("people")
15111511
15121512// SQL statements can be run by using the sql methods provided by sqlContext.
15131513val teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19")
@@ -1544,8 +1544,8 @@ people.printSchema();
15441544// |-- age: long (nullable = true)
15451545// |-- name: string (nullable = true)
15461546
1547- // Register this DataFrame as a table.
1548- people.registerTempTable ("people");
1547+ // Creates a temporary view using the DataFrame
1548+ people.createOrReplaceTempView ("people");
15491549
15501550// SQL statements can be run by using the sql methods provided by sqlContext.
15511551DataFrame teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19");
@@ -1582,8 +1582,8 @@ people.printSchema()
15821582# |-- age: long (nullable = true)
15831583# |-- name: string (nullable = true)
15841584
1585- # Register this DataFrame as a table .
1586- people.registerTempTable ("people")
1585+ # Creates a temporary view using the DataFrame .
1586+ people.createOrReplaceTempView ("people")
15871587
15881588# SQL statements can be run by using the sql methods provided by ` sqlContext ` .
15891589teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND age <= 19")
0 commit comments