{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/32143873","id":32143873,"diff_hunk":"@@ -0,0 +1,101 @@\n+#\n+# Licensed to the Apache Software Foundation (ASF) under one or more\n+# contributor license agreements.  See the NOTICE file distributed with\n+# this work for additional information regarding copyright ownership.\n+# The ASF licenses this file to You under the Apache License, Version 2.0\n+# (the \"License\"); you may not use this file except in compliance with\n+# the License.  You may obtain a copy of the License at\n+#\n+#    http://www.apache.org/licenses/LICENSE-2.0\n+#\n+# Unless required by applicable law or agreed to in writing, software\n+# distributed under the License is distributed on an \"AS IS\" BASIS,\n+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+# See the License for the specific language governing permissions and\n+# limitations under the License.\n+#\n+\n+# For this example, we shall use the \"flights\" dataset\n+# The dataset consists of every flight departing Houston in 2011.\n+# The data set is made up of 227,496 rows x 14 columns. \n+\n+# Load SparkR library into your R session\n+library(SparkR)\n+\n+args <- commandArgs(trailing = TRUE)\n+\n+## Initialize SparkContext\n+sc <- sparkR.init(appName = \"SparkR-data-manipulation-example\")\n+\n+## Initialize SQLContext\n+sqlContext <- sparkRSQL.init(sc)\n+\n+if (length(args) != 1) {\n+  print(\"Usage: data-manipulation.R <path-to-flights.csv\")\n+  print(\"The data can be downloaded from: http://s3-us-west-2.amazonaws.com/sparkr-data/flights.csv \")\n+  q(\"no\")\n+}\n+\n+flightsCsvPath <- args[[1]]\n+\n+\n+# Create a local R dataframe\n+flights_df <- read.csv(flightsCsvPath, header = TRUE)\n+flights_df$date <- as.Date(flights_df$date)\n+\n+## Filter flights whose destination is San Francisco and write to a local data frame\n+SFO_df <- flights_df[flights_df$dest == \"SFO\", ] \n+\n+# Convert the local data frame into a SparkR DataFrame\n+SFO_DF <- createDataFrame(sqlContext, SFO_df)\n+\n+#  Directly create a SparkR DataFrame from the source data\n+flightsDF <- read.df(sqlContext, flightsCsvPath, source = \"csv\", header = \"true\")\n+\n+# Print the schema of this Spark DataFrame\n+printSchema(flightsDF)\n+\n+# Cache the DataFrame\n+cache(flightsDF)\n+\n+# Print the first 6 rows of the DataFrame\n+showDF(flightsDF, numRows = 6) ## Or\n+head(flightsDF)\n+\n+# Show the column names in the DataFrame\n+columns(flightsDF)\n+\n+# Show the number of rows in the DataFrame\n+count(flightsDF)\n+\n+# Show summary statistics for numeric colums\n+describe(flightsDF)\n+\n+# Select specific columns\n+destDF <- select(flightsDF, \"dest\", \"cancelled\")\n+\n+# Using SQL to select columns of data\n+# First, register the flights DataFrame as a table\n+registerTempTable(flightsDF, \"flightsTable\")\n+destDF <- sql(sqlContext, \"SELECT dest, cancelled FROM flightsTable\")\n+\n+# Use collect to create a local R data frame\n+local_df <- collect(destDF)\n+\n+# Print the newly created local data frame\n+print(local_df)\n+\n+# Filter flights whose destination is JFK\n+jfkDF <- filter(flightsDF, \"dest == JFK\") ##OR","path":"examples/src/main/r/data-manipulation.R","position":89,"original_position":89,"commit_id":"3a97867dfddd8ecd96a676b757d818f05cae4dc8","original_commit_id":"3a97867dfddd8ecd96a676b757d818f05cae4dc8","user":{"login":"rxin","id":323388,"avatar_url":"https://avatars.githubusercontent.com/u/323388?v=3","gravatar_id":"","url":"https://api.github.com/users/rxin","html_url":"https://github.com/rxin","followers_url":"https://api.github.com/users/rxin/followers","following_url":"https://api.github.com/users/rxin/following{/other_user}","gists_url":"https://api.github.com/users/rxin/gists{/gist_id}","starred_url":"https://api.github.com/users/rxin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rxin/subscriptions","organizations_url":"https://api.github.com/users/rxin/orgs","repos_url":"https://api.github.com/users/rxin/repos","events_url":"https://api.github.com/users/rxin/events{/privacy}","received_events_url":"https://api.github.com/users/rxin/received_events","type":"User","site_admin":false},"body":"Technically we can be error tolerant and support == in the parser though. I can't think of a corner case that'd be problematic. ","created_at":"2015-06-10T17:36:01Z","updated_at":"2015-06-10T17:36:01Z","html_url":"https://github.com/apache/spark/pull/6668#discussion_r32143873","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6668","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/32143873"},"html":{"href":"https://github.com/apache/spark/pull/6668#discussion_r32143873"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6668"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6668","id":37013060,"html_url":"https://github.com/apache/spark/pull/6668","diff_url":"https://github.com/apache/spark/pull/6668.diff","patch_url":"https://github.com/apache/spark/pull/6668.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6668","number":6668,"state":"open","locked":false,"title":"[SPARK-8124] [SPARKR]  [WIP] Created more examples on SparkR DataFrames","user":{"login":"Emaasit","id":7738216,"avatar_url":"https://avatars.githubusercontent.com/u/7738216?v=3","gravatar_id":"","url":"https://api.github.com/users/Emaasit","html_url":"https://github.com/Emaasit","followers_url":"https://api.github.com/users/Emaasit/followers","following_url":"https://api.github.com/users/Emaasit/following{/other_user}","gists_url":"https://api.github.com/users/Emaasit/gists{/gist_id}","starred_url":"https://api.github.com/users/Emaasit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Emaasit/subscriptions","organizations_url":"https://api.github.com/users/Emaasit/orgs","repos_url":"https://api.github.com/users/Emaasit/repos","events_url":"https://api.github.com/users/Emaasit/events{/privacy}","received_events_url":"https://api.github.com/users/Emaasit/received_events","type":"User","site_admin":false},"body":"Here are more examples on SparkR DataFrames including creating a Spark Contect and a SQL\r\ncontext, loading data and simple data manipulation.","created_at":"2015-06-05T09:05:51Z","updated_at":"2015-06-10T17:36:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"70ae0217524fe2172931716360898d80fb5c580a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6668/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6668/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6668/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/3a97867dfddd8ecd96a676b757d818f05cae4dc8","head":{"label":"Emaasit:dan-dev","ref":"dan-dev","sha":"3a97867dfddd8ecd96a676b757d818f05cae4dc8","user":{"login":"Emaasit","id":7738216,"avatar_url":"https://avatars.githubusercontent.com/u/7738216?v=3","gravatar_id":"","url":"https://api.github.com/users/Emaasit","html_url":"https://github.com/Emaasit","followers_url":"https://api.github.com/users/Emaasit/followers","following_url":"https://api.github.com/users/Emaasit/following{/other_user}","gists_url":"https://api.github.com/users/Emaasit/gists{/gist_id}","starred_url":"https://api.github.com/users/Emaasit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Emaasit/subscriptions","organizations_url":"https://api.github.com/users/Emaasit/orgs","repos_url":"https://api.github.com/users/Emaasit/repos","events_url":"https://api.github.com/users/Emaasit/events{/privacy}","received_events_url":"https://api.github.com/users/Emaasit/received_events","type":"User","site_admin":false},"repo":{"id":36921679,"name":"spark","full_name":"Emaasit/spark","owner":{"login":"Emaasit","id":7738216,"avatar_url":"https://avatars.githubusercontent.com/u/7738216?v=3","gravatar_id":"","url":"https://api.github.com/users/Emaasit","html_url":"https://github.com/Emaasit","followers_url":"https://api.github.com/users/Emaasit/followers","following_url":"https://api.github.com/users/Emaasit/following{/other_user}","gists_url":"https://api.github.com/users/Emaasit/gists{/gist_id}","starred_url":"https://api.github.com/users/Emaasit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Emaasit/subscriptions","organizations_url":"https://api.github.com/users/Emaasit/orgs","repos_url":"https://api.github.com/users/Emaasit/repos","events_url":"https://api.github.com/users/Emaasit/events{/privacy}","received_events_url":"https://api.github.com/users/Emaasit/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Emaasit/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/Emaasit/spark","forks_url":"https://api.github.com/repos/Emaasit/spark/forks","keys_url":"https://api.github.com/repos/Emaasit/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Emaasit/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Emaasit/spark/teams","hooks_url":"https://api.github.com/repos/Emaasit/spark/hooks","issue_events_url":"https://api.github.com/repos/Emaasit/spark/issues/events{/number}","events_url":"https://api.github.com/repos/Emaasit/spark/events","assignees_url":"https://api.github.com/repos/Emaasit/spark/assignees{/user}","branches_url":"https://api.github.com/repos/Emaasit/spark/branches{/branch}","tags_url":"https://api.github.com/repos/Emaasit/spark/tags","blobs_url":"https://api.github.com/repos/Emaasit/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Emaasit/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Emaasit/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/Emaasit/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Emaasit/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/Emaasit/spark/languages","stargazers_url":"https://api.github.com/repos/Emaasit/spark/stargazers","contributors_url":"https://api.github.com/repos/Emaasit/spark/contributors","subscribers_url":"https://api.github.com/repos/Emaasit/spark/subscribers","subscription_url":"https://api.github.com/repos/Emaasit/spark/subscription","commits_url":"https://api.github.com/repos/Emaasit/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/Emaasit/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/Emaasit/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/Emaasit/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/Emaasit/spark/contents/{+path}","compare_url":"https://api.github.com/repos/Emaasit/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Emaasit/spark/merges","archive_url":"https://api.github.com/repos/Emaasit/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Emaasit/spark/downloads","issues_url":"https://api.github.com/repos/Emaasit/spark/issues{/number}","pulls_url":"https://api.github.com/repos/Emaasit/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/Emaasit/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/Emaasit/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Emaasit/spark/labels{/name}","releases_url":"https://api.github.com/repos/Emaasit/spark/releases{/id}","created_at":"2015-06-05T08:35:10Z","updated_at":"2015-06-05T08:35:32Z","pushed_at":"2015-06-10T11:08:51Z","git_url":"git://github.com/Emaasit/spark.git","ssh_url":"git@github.com:Emaasit/spark.git","clone_url":"https://github.com/Emaasit/spark.git","svn_url":"https://github.com/Emaasit/spark","homepage":null,"size":108667,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"da20c8ca37663738112b04657057858ee3e55072","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-06-10T17:24:16Z","pushed_at":"2015-06-10T16:46:13Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1437002,"stargazers_count":4289,"watchers_count":4289,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3771,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":355,"forks":3771,"open_issues":355,"watchers":4289,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6668"},"html":{"href":"https://github.com/apache/spark/pull/6668"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6668"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6668/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6668/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6668/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/3a97867dfddd8ecd96a676b757d818f05cae4dc8"}}}}