[Solved] CSE 344 Homework 7: JSON, NoSQL, and AsterixDB
5.0
1 customer review
Digital download
Digital download
$25.00
Message us on WhatsApp for payment or download support.
Open WhatsApp
mondial.adm (the entire dataset), country, mountain, and sea (three subsets)apache-asterixdb-0.9.4.zip and unzip it anywhere youd like.export JAVA_HOME=/usr/lib/jvm/[SOME JAVA 8 folder]<path to mondial.adm>. Then press Run:q1.sqlp), then execute the query by typing the following command in terminal:This will print the output on the screen. If there is too much output, you can save it to a fileYou can now view output.txt using your favorite text editor.USE geo;Try this query to see if things are running correctly: SELECT y.`-car_code` as code, y.name as name FROM geo.world x, x.mondial.country y ORDER BY y.name;stop-sample-cluster.sh in the terminal. The script is located in opt/local/bin (or optlocalbinstop-sample-cluster.bat on windows).mondial.adm dataset for problems 1-9.
city. [Result Size: 30 rows of {"city":...}]country, population, num_religions. [Result Size: 238 rows of {"num_religions":..., "country":..., "population":...} (order of keys can differ)]religion, num_countries. [Result size: 37 of {"religion':..., "num_countries":...} (order of keys can differ)]float(x) and/or int(x) to convert a string to a float or to an int. Name your output attributes ethnic_group, num_countries, total_population. You can leave your final total_population as a float if you like. [Result Size: 262 of {"ethnic_group":..., "num_countries":..., "total_population":...} (order of keys can differ)]mountain, height, country_code, country_name. [Result Size: 272 rows of {"mountain":..., "height":..., "country_code":..., "country_name":...} (order of keys can differ)]Hint: Some mountains can be located in more than one country. You need to output them for each country they are located in.country_code, country_name, mountains. The attribute mountains should be a list of objects, each with the attributes mountain and height. [Result Size: 238 rows of {"country_code":..., "country_name":..., "mountains": [{"mountain":..., "height":...}, {"mountain":..., "height":...}, ...]} (order of keys can differ)]country_code, country_name, seas. The attribute seas should be a list of objects, each with the attribute sea. [Result Size: 74 rows of {"country_code":..., "country_name":..., "seas": [{"sea":...}, {"sea":...}, ...]} (order of keys can differ)]country_code, country_name, area. [Result Size: 45 rows of {"country_code":..., "country_name":..., "area":...} (order of keys can differ)]first_country, second_country. [Result Size: 7 rows of {"first_country":..., "second_country":...}]countryType, the dataset country, and a BTREE index on the attribute -car_code, which is also the primary key. Both types are OPEN, which means that they may have other fields besides the three required fields -car_code, -area, and population.Create two new types: mountainType and seaType, and two new datasets, mountain and sea. Both should have two required fields: -id and -country. Their key should be autogenerated, and of type uuid (see how we did it for the mondial dataset). Create an index of type KEYWORD (instead of BTREE) on the -country field (for both mountain and sea). Turn in the complete sequence of commands for creating all three types, datasets, and indices (for country, mountain, sea).Recall from lecture that asterix only allows creating index at top level collection, hence we provide the country, sea, etc collections individually even though their data is already included in mondial.geoindex. Report the new runtime. [Result Size: 7 rows of {"first_country":..., "second_country":...}]first_country, second_country, mountain, sea. [Result Size: 7 rows of {"mountains":[{"mountain":...}, ...], "seas":[{"sea":...}, ...], "first_country":..., "second_country":...}]DROP DATAVERSE geo IF EXISTS; CREATE DATAVERSE geo; CREATE TYPE geo.worldType AS {auto_id:uuid }; CREATE DATASET geo.world(worldType) PRIMARY KEY auto_id AUTOGENERATED; LOAD DATASET geo.world USING localfs (("path"="127.0.0.1:///<path to mondial.adm>, e.g., /home/auser/344/hw/geo/mondial.adm"),("format"="adm")); /* Edit the absolute path above to point to your copy of mondial.adm. */ /* Use '/' instead of '' in a path for Windows. e.g., C:/344/hw/geo/mondial.adm. */
curl -v --data-urlencode "statement=`cat q1.sqlp`" --data pretty=true http://localhost:19002/query/service
curl -v --data-urlencode "statement=`cat q1.sqlp`" --data pretty=true http://localhost:19002/query/service > output.txt
-- return the set of countriesSELECT x.mondial.country FROM geo.world x;
-- return each country, one by one (see the difference?)SELECT y as country FROM geo.world x, x.mondial.country y;
-- return just their codes, and their names, alphabetically-- notice that -car_code is not a legal field name, so we enclose in ` `SELECT y.`-car_code` as code, y.name as nameFROM geo.world x, x.mondial.country y order by y.name;
-- this query will NOT run...SELECT z.name as province_name, u.name as city_nameFROM geo.world x, x.mondial.country y, y.province z, z.city uWHERE y.name='Hungary';-- ...because some provinces have a single city, others have a list of cities; fix it:SELECT z.name as province_name, u.name as city_nameFROM geo.world x, x.mondial.country y, y.province z, CASE WHEN is_array(z.city) THEN z.city ELSE [z.city] END uWHERE y.name='Hungary';
-- same, but return the city names as a nested collection; -- note correct treatment of missing cities-- also note the convenient LET construct (see SQL++ documentation)SELECT z.name as province_name, (select u.name from cities u)FROM geo.world x, x.mondial.country y, y.province zLET cities = CASE WHEN z.city is missing THEN [] WHEN is_array(z.city) THEN z.city ELSE [z.city] ENDWHERE y.name='Hungary';