Github user marmbrus commented on a diff in the pull request: https://github.com/apache/spark/pull/4446#discussion_r24432619 --- Diff: python/pyspark/sql_tests.py --- @@ -285,6 +285,38 @@ def test_aggregator(self): self.assertTrue(95 < g.agg(Dsl.approxCountDistinct(df.key)).first()[0]) self.assertEqual(100, g.agg(Dsl.countDistinct(df.value)).first()[0]) + def test_save_and_load(self): + df = self.df + tmpPath = tempfile.mkdtemp() + shutil.rmtree(tmpPath) + df.save(tmpPath, "org.apache.spark.sql.json", "error") + actual = self.sqlCtx.load(tmpPath, "org.apache.spark.sql.json") + self.assertTrue(sorted(df.collect()) == sorted(actual.collect())) + + from pyspark.sql import StructType, StructField, StringType + schema = StructType([StructField("value", StringType(), True)]) + actual = self.sqlCtx.load(tmpPath, "org.apache.spark.sql.json", schema) + self.assertTrue(sorted(df.select("value").collect()) == sorted(actual.collect())) + + df.save(tmpPath, "org.apache.spark.sql.json", "overwrite") + actual = self.sqlCtx.load(tmpPath, "org.apache.spark.sql.json") + self.assertTrue(sorted(df.collect()) == sorted(actual.collect())) + + df.save(dataSourceName="org.apache.spark.sql.json", mode="overwrite", path=tmpPath, + noUse="this options will not be used in save.") + actual = self.sqlCtx.load(dataSourceName="org.apache.spark.sql.json", path=tmpPath, + noUse="this options will not be used in load.") + self.assertTrue(sorted(df.collect()) == sorted(actual.collect())) + + defaultDataSourceName = self.sqlCtx._ssql_ctx.getConf("spark.sql.sources.default", + "org.apache.spark.sql.parquet") + self.sqlCtx.sql("SET spark.sql.sources.default=org.apache.spark.sql.json") --- End diff -- I think we should just try org.apache.spark.sql.* whenever what they give us fails to resolve on its own. On Feb 10, 2015 9:43 AM, "Yin Huai" <notificati...@github.com> wrote: > In python/pyspark/sql_tests.py > <https://github.com/apache/spark/pull/4446#discussion_r24432467>: > > > + actual = self.sqlCtx.load(tmpPath, "org.apache.spark.sql.json", schema) > > + self.assertTrue(sorted(df.select("value").collect()) == sorted(actual.collect())) > > + > > + df.save(tmpPath, "org.apache.spark.sql.json", "overwrite") > > + actual = self.sqlCtx.load(tmpPath, "org.apache.spark.sql.json") > > + self.assertTrue(sorted(df.collect()) == sorted(actual.collect())) > > + > > + df.save(dataSourceName="org.apache.spark.sql.json", mode="overwrite", path=tmpPath, > > + noUse="this options will not be used in save.") > > + actual = self.sqlCtx.load(dataSourceName="org.apache.spark.sql.json", path=tmpPath, > > + noUse="this options will not be used in load.") > > + self.assertTrue(sorted(df.collect()) == sorted(actual.collect())) > > + > > + defaultDataSourceName = self.sqlCtx._ssql_ctx.getConf("spark.sql.sources.default", > > + "org.apache.spark.sql.parquet") > > + self.sqlCtx.sql("SET spark.sql.sources.default=org.apache.spark.sql.json") > > @davies <https://github.com/davies> You meant a shorter name for the conf > key "spark.sql.sources.default"? > > â > Reply to this email directly or view it on GitHub > <https://github.com/apache/spark/pull/4446/files#r24432467>. >
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org