-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathhd.hive.json.table.py
executable file
·113 lines (104 loc) · 2.84 KB
/
hd.hive.json.table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env python3
############################################################################
#
# MODULE: hd.hive.json.table
# AUTHOR(S): Matej Krejci ([email protected]
#
# COPYRIGHT: (C) 2016 by the GRASS Development Team
#
# This program is free software under the GNU General
# Public License (>=v2). Read the file COPYING that
# comes with GRASS for details.
#
#############################################################################
# %module
# % description: Creating Hive spatial tables for storing Json map
# % keyword: database
# % keyword: hdfs
# % keyword: hive
# %end
# %option
# % key: driver
# % type: string
# % required: yes
# % answer: hiveserver2
# % description: Type of database driver
# % options: hive_cli,hiveserver2
# % guisection: table
# %end
# %option
# % key: table
# % type: string
# % required: yes
# % description: name of table
# % guisection: table
# %end
# %option
# % key: columns
# % type: string
# % guisection: table
# %end
# %option
# % key: stored
# % type: string
# % required: no
# % description: output
# % guisection: table
# %end
# %option
# % key: serde
# % type: string
# % required: yes
# % answer: org.openx.data.jsonserde.JsonSerDe
# % description: java class for serialization of json
# % guisection: table
# %end
# %option
# % key: outformat
# % type: string
# % description: java class for handling output format
# % guisection: table
# %end
# %option
# % key: jsonpath
# % type: string
# % description: hdfs path specifying input data
# % guisection: data
# %end
# %flag
# % key: o
# % description: Possible if filepath for loading data is delcared. True-overwrite all data in table.
# % guisection: data
# %end
# %flag
# % key: d
# % description: Firstly drop table if exists
# % guisection: table
# %end
# %flag
# % key: e
# % description: The EXTERNAL keyword lets you create a table and provide a LOCATION so that Hive does not use a default location for this table. This comes in handy if you already have data generated. When dropping an EXTERNAL table, data in the table is NOT deleted from the file system.
# % guisection: table
# %end
import grass.script as gs
from hdfsgrass.hdfs_grass_lib import ConnectionManager
def main():
if not options["columns"] and not options["struct"]:
gs.fatal("Must be defined <attributes> or <struct> parameter")
conn = ConnectionManager()
conn.get_current_connection(options["driver"])
hive = conn.get_hook()
hive.create_geom_table(
table=options["table"],
field=options["columns"],
stored=options["stored"],
serde=options["serde"],
outputformat=options["outformat"],
external=flags["e"],
recreate=flags["d"],
filepath=options["jsonpath"],
overwrite=flags["o"],
)
if __name__ == "__main__":
options, flags = gs.parser()
main()