Skip to content

Commit e363017

Browse files
committed
[cdt-63] :added twitter files
Signed-off-by: ashish <[email protected]>
1 parent dbd62fd commit e363017

File tree

10 files changed

+66
-16
lines changed

10 files changed

+66
-16
lines changed

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ node_modules
99
/.idea
1010
cdt.iml
1111
**/.DS_Store
12-
output/*
13-
!output/.gitkeep
12+
13+
output/*.json
14+
output/*.avro
15+
output/*.avsc
16+
1417
coverage/*.json
18+
19+

src/commands/avro.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ export default class Avro extends Command {
1212
static GET_SCHEMA = 'get_schema'
1313
static TO_JSON = 'to_json'
1414
static TO_AVRO = 'to_avro'
15+
static TO_CSV = 'to_csv'
1516

1617
// do not change order otherwise we need to change order in getCommand() also
17-
static SupportedCommands = [Avro.GET_SCHEMA, Avro.TO_JSON, Avro.TO_AVRO]
18+
static SupportedCommands = [Avro.GET_SCHEMA, Avro.TO_JSON, Avro.TO_AVRO, Avro.TO_CSV]
1819
static flags = {
1920
help: flags.help({char: 'h'}),
2021
file: flags.string({char: 'f' , description: 'input file path'}),
@@ -52,12 +53,14 @@ export default class Avro extends Command {
5253

5354
private executeCommand(flags: any, args: any) {
5455
switch (args.command) {
55-
case Avro.SupportedCommands[0]:
56+
case Avro.GET_SCHEMA:
5657
return this.getSchema(flags, args)
57-
case Avro.SupportedCommands[1]:
58+
case Avro.TO_JSON:
5859
return this.toJson(flags, args)
59-
case Avro.SupportedCommands[2]:
60+
case Avro.TO_AVRO:
6061
return this.toAvro(flags, args)
62+
// case Avro.TO_CSV:
63+
// return this.toCsv(flags, args)
6164
default:
6265
Logger.error(this, 'Unsupported Command, supported: ' + Avro.SupportedCommands)
6366
}
@@ -92,6 +95,28 @@ export default class Avro extends Command {
9295
Logger.success(this, `${chalk.blue('Json')} written to file: ${chalk.green(flags.output)}`) // this will output error and exit command
9396
}
9497

98+
// // tslint:disable-next-line:no-unused
99+
// private toCsv(flags: any, args: any) {
100+
// var json2Csv = require("json-2-csv")
101+
//
102+
// let json=`
103+
// {
104+
// "created_at": "Thu May 10 15:24:15 +0000 2018",
105+
// "id_str": "850006245121695744",
106+
// "text": "Here is the Tweet message.",
107+
// "user": {
108+
// },
109+
// "place": {
110+
// },
111+
// "entities": {
112+
// },
113+
// "extended_entities": {
114+
// }
115+
// }
116+
// `
117+
//
118+
// }
119+
95120
private toAvro(flags: any, args: any) {
96121
if (!flags.schemaType)
97122
Logger.error(this, 'Schema file is not provided')

test/commands/avro.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {expect, test} from '@oclif/test'
2+
import {readFileSync} from 'fs'
23

34
describe('avro', () => {
45
//todo if file is invalid
@@ -59,15 +60,16 @@ describe('avro', () => {
5960
})
6061

6162

62-
test
63-
.stdout()
64-
.command(['avro', '-f', 'test/resources/avro/person.avro', '-o', 'test/resources/avro/output/person.json','to_json'])
65-
.it('if to_json commands run with success', ctx => {
66-
expect(ctx.stdout).to.contain('success')
67-
})
63+
// test
64+
// .stdout()
65+
// .command(['avro', '-f', 'test/resources/avro/person.avro', '-o', 'test/resources/avro/output/person.json','to_json'])
66+
// .it('if to_json commands run with success', ctx => {
67+
// expect(ctx.stdout).to.contain('success')
68+
// let buffer = readFileSync("test/resources/avro/output/person.json")
69+
// expect(buffer.toJSON()).to.contain()
70+
// })
6871

6972
test
70-
.timeout(20000) // added timeout to resolve timeout problem
7173
.stdout()
7274
.command(['avro', '-f', 'test/resources/avro/person.json', '-o', 'test/resources/avro/output/person.avro', '-t', 'test/resources/avro/person.avsc', 'to_avro'])
7375
.it('if to_avro commands run with success', ctx => {
-158 KB
Binary file not shown.

test/resources/avro/output/person.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/resources/avro/twitter.avro

465 Bytes
Binary file not shown.

test/resources/avro/twitter.avsc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"type" : "record",
3+
"name" : "twitter_schema",
4+
"namespace" : "com.miguno.avro",
5+
"fields" : [ {
6+
"name" : "username",
7+
"type" : "string",
8+
"doc" : "Name of the user account on Twitter.com"
9+
}, {
10+
"name" : "tweet",
11+
"type" : "string",
12+
"doc" : "The content of the user's Twitter message"
13+
}, {
14+
"name" : "timestamp",
15+
"type" : "long",
16+
"doc" : "Unix epoch time in seconds"
17+
} ],
18+
"doc:" : "A basic schema for storing Twitter messages"
19+
}

test/resources/avro/twitter.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"username":"miguno","tweet":"Rock: Nerf paper, scissors is fine.","timestamp": 1366150681 }
2+
{"username":"BlizzardCS","tweet":"Works as intended. Terran is IMBA.","timestamp": 1366154481 }

test/resources/output/ouput.css

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/resources/output/out.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)