The JSON data processing of spark

Source: Internet
Author: User

--by default, the Sparkcontext object is initialized with Namesc when Spark-shell is started. Use the following command to create the SqlContext. Val SqlContext=New Org.apache.spark.sql.SQLContext (SC)--employee.json-Place this file in the same directory as the currentscala> pointer. {{"id": "1201"," name ":" Satish "," Age ":" -"} {"id": "1202"," name ":" Krishna "," Age ":" -"} {"id": "1203"," name ":" Amith "," Age ":" the"} {"id": "1204"," name ":" Javed "," Age ":" at"} {"id": "1205"," name ":" Prudvi "," Age ":" at"}}--reads the JSON document Namedemployee.json. The data is displayed as a table with fields Id,name and age. Val Dfs=SqlContext.Read. JSON ("/Root/Wangbin/Employee.json ")--Show Datadfs.show ()--View Data StructuresDfs.printschema ()--View a columnDfs.Select("name"). Show ()--look for employees older than (Age> 23). Dfs.filter (Dfs ("age")>  at). Show ()--calculate the number of employees at the same age. Dfs.groupby ("Age").Count(). Show ()

The JSON data processing of spark

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.