Load JSON file in Pig script inside Hortonworks Sandbox - json

I'm new to the whole Hadoop/Hortonworks/Pig stuff, so excuse me for the question.
I have installed the Hortonworks Sandbox. I'm trying to load a twitter JSON file and perform some queries on the file, but I'm currently stuck in the loading file part.
I know that I should use the Elephant-bird in order to load a JSON file (without specifying the JSON schema) with JsonLoader(), so I've downloaded the Elephant-bird from the git repo and I've included the jar file
Elephant-bird\repo\com\twitter\elephant-bird\2.2.3\elephant-bird-2.2.3.jar
inside the Hortonworks Sandbox. Here a screen shot with my Pig script:
REGISTER elephant-bird-2.2.3.jar;
Json1 = LOAD 'JSON/sample.tweets' JsonLoader();
DESCRIBE Json1;
STORE Json1 INTO 'tweeterOutput';
Unfortunately I cannot get any results from this script execution. I've tried with both STORE and DUMP commands.
Probably I'm doing many wrong things in this process flow, so any help will be appreciated!

You are missing the USING keyword:
Json1 = LOAD 'JSON/sample.tweets' USING JsonLoader();

Fix the below
You need to add few more jars: elephant-bird-core-4.4.jar, elephant-bird-pig-4.4.jar, elephant-bird-hadoop-compat-4.4.jar, json-simple-1.1.1.jar
Register all of them in the script
REGISTER elephant-bird-core-4.4.jar;
REGISTER elephant-bird-pig-4.4.jar;
REGISTER elephant-bird-hadoop-compat-4.4.jar;
REGISTER json-simple-1.1.1.jar;
LOAD 'JSON/sample.tweets' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad');

Related

What would be the best way to write JSON in a locally stored file in React Native

Im currently working on a new design for a mobile app (only frontend). In the project I need to use states to change the css of a button. If the button has changed, next time the app is refreshed the state should be as you left it.
That is why I have a locally stored JSON file that is structured the same as how the apps current database is. Reading it is no issue, but I can't get the writing to work.
How I read the JSON:
const jsonData = require('../data.json')
function GetBaseState(id){
console.log(jsonData.bases[id].state)
}
How would I go about changing that state in the JSON file?
In order to both of reading and writing Json file , you are able to use react-native-fs. For example by readFile method you can read json file and by writeFile method writing your json file in local storage.
react-native-fs have good documents that you are able to reading that for more information and usage.

Remove a local JSON file by code in flutter

I wrote an app that fills a database from a local JSON file, and the app doesn't use this file after that.
Is there a way to remove it by code (by deleting it for example)?
Thanks.

File not found when run project from browser

I write a function to read data from excel file, then generate whole datas to JSON. When i test running as application, it works well. But when i call that function into Servlet class and using browser to run it, the file not found exception come. I put the excel file to root folder of my project and URI is the same. Is there any one have ever had same issue with me? and know how to fix it? Thank.

Open local JSON file for examination

I was wondering if it's possible to open a local JSON file so I can just check its structure? Didn't/don't want to upload the file to an online JSON format checker site and was hoping I can just utilize PAW to do that.
Don't seem to be able to do this with a local file, unless I run it through a local server, eg using MAMP, unless I missed something...?
Thanks.
You could copy the content into the txt body then switch to the JSON body this will let you view it in the nice structure, sorry currently no way to directly import a file need to copy past the content.
Take a look at jsonlint npm module. Supports JSON schema validation and pretty printing.

Read and Write file using vs code extension

i am building an extension to parse json using vs code extension.
so my need is ,it should be able able to load .json file from a particular folder and iterate through content of the file.
Then it should allow user to select few keys from it make a new json file out of this and save it in any folder.
But i am not able to find any way to read and write files in "vs code extension".Could someone please help me.
If you want to read the current edit state of a file you can use the following API workspace function:
vscode.workspace.openTextDocument(uri).then((document) => {
let text = document.getText();
});
This will show you the current state of the file including unpersisted changes. document is of type TextDocument and has isDirty set to true if it has pending changes.
Since the extension runs in nodejs, you should be able to use any nodejs module built-in or installed by npm in the usual way.
For your purpose you will be OK with the built-in fs module: https://nodejs.org/dist/latest-v6.x/docs/api/fs.html
In your extension you will need to import the required module, so your code file should contain this:
let fs = require("fs");
and then use the methods in the usual way, eg. fs.fileReadSync( filename, encoding ) ...
Please not that there is one exception. If you install a nodejs module containing compiled, binary code, it will not run in the extension and instead you will see an error message saying something like %1 is not a valid Win32 application. Pure javascript modules are OK, though.
VSCode extensions are running in node.js. Therefore you can use any available node.js package/module within your extension. For instance, check out this question for reading JSON.
For JSON, you just need to require or import the JSON file, such as:
const jsonObject = require('./myJSONfile.json');
// do something
For JSON with comments, you can use node-jsonc-parser.
After the manipulation, you could use the fs module of nodej.js to write to the disk.