@openfn/language-hive 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/LICENSE.LESSER +165 -0
- package/README.md +31 -0
- package/ast.json +562 -0
- package/configuration-schema.json +61 -0
- package/dist/index.cjs +153 -0
- package/dist/index.js +130 -0
- package/package.json +49 -0
- package/types/Adaptor.d.ts +27 -0
- package/types/index.d.ts +3 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/index.js
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
dataPath: () => import_language_common2.dataPath,
|
|
29
|
+
dataValue: () => import_language_common2.dataValue,
|
|
30
|
+
dateFns: () => import_language_common2.dateFns,
|
|
31
|
+
default: () => src_default,
|
|
32
|
+
each: () => import_language_common2.each,
|
|
33
|
+
execute: () => execute,
|
|
34
|
+
field: () => import_language_common2.field,
|
|
35
|
+
fields: () => import_language_common2.fields,
|
|
36
|
+
fn: () => import_language_common2.fn,
|
|
37
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
38
|
+
merge: () => import_language_common2.merge,
|
|
39
|
+
parseCsv: () => import_language_common2.parseCsv,
|
|
40
|
+
query: () => query,
|
|
41
|
+
sourceValue: () => import_language_common2.sourceValue
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(src_exports);
|
|
44
|
+
|
|
45
|
+
// src/Adaptor.js
|
|
46
|
+
var Adaptor_exports = {};
|
|
47
|
+
__export(Adaptor_exports, {
|
|
48
|
+
dataPath: () => import_language_common2.dataPath,
|
|
49
|
+
dataValue: () => import_language_common2.dataValue,
|
|
50
|
+
dateFns: () => import_language_common2.dateFns,
|
|
51
|
+
each: () => import_language_common2.each,
|
|
52
|
+
execute: () => execute,
|
|
53
|
+
field: () => import_language_common2.field,
|
|
54
|
+
fields: () => import_language_common2.fields,
|
|
55
|
+
fn: () => import_language_common2.fn,
|
|
56
|
+
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
57
|
+
merge: () => import_language_common2.merge,
|
|
58
|
+
parseCsv: () => import_language_common2.parseCsv,
|
|
59
|
+
query: () => query,
|
|
60
|
+
sourceValue: () => import_language_common2.sourceValue
|
|
61
|
+
});
|
|
62
|
+
var import_language_common = require("@openfn/language-common");
|
|
63
|
+
var import_util = require("@openfn/language-common/util");
|
|
64
|
+
var import_hive_driver = __toESM(require("hive-driver"), 1);
|
|
65
|
+
var import_language_common2 = require("@openfn/language-common");
|
|
66
|
+
var { TCLIService, TCLIService_types } = import_hive_driver.default.thrift;
|
|
67
|
+
var utils = new import_hive_driver.default.HiveUtils(TCLIService_types);
|
|
68
|
+
var client = null;
|
|
69
|
+
var session = null;
|
|
70
|
+
var hiveClient = new import_hive_driver.default.HiveClient(TCLIService, TCLIService_types);
|
|
71
|
+
var connection = new import_hive_driver.default.connections.TcpConnection();
|
|
72
|
+
function execute(...operations) {
|
|
73
|
+
const initialState = {
|
|
74
|
+
references: [],
|
|
75
|
+
data: null
|
|
76
|
+
};
|
|
77
|
+
return (state) => {
|
|
78
|
+
return (0, import_language_common.execute)(
|
|
79
|
+
connect,
|
|
80
|
+
...operations,
|
|
81
|
+
disconnect
|
|
82
|
+
)({
|
|
83
|
+
...initialState,
|
|
84
|
+
...state
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function connect(state) {
|
|
89
|
+
const { host, port, username, password } = state.configuration;
|
|
90
|
+
const auth = username && password ? new import_hive_driver.default.auth.PlainTcpAuthentication({
|
|
91
|
+
username,
|
|
92
|
+
password
|
|
93
|
+
}) : new import_hive_driver.default.auth.NoSaslAuthentication();
|
|
94
|
+
client = await hiveClient.connect({ host, port }, connection, auth);
|
|
95
|
+
session = await client.openSession({
|
|
96
|
+
client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
|
|
97
|
+
});
|
|
98
|
+
console.log("Connect client");
|
|
99
|
+
return state;
|
|
100
|
+
}
|
|
101
|
+
async function disconnect(state) {
|
|
102
|
+
console.log("Disconnect client");
|
|
103
|
+
await session.close();
|
|
104
|
+
await client.close();
|
|
105
|
+
return state;
|
|
106
|
+
}
|
|
107
|
+
function query(qs, options, callback) {
|
|
108
|
+
return async (state) => {
|
|
109
|
+
const [resolvedQs, resolvedOptions] = (0, import_util.expandReferences)(state, qs, options);
|
|
110
|
+
console.log(`Executing query: ${resolvedQs}`);
|
|
111
|
+
const result = await execSql(resolvedQs, resolvedOptions);
|
|
112
|
+
console.log("Success... \u2714");
|
|
113
|
+
console.log("Retrieved", result.length, "items");
|
|
114
|
+
const nextState = {
|
|
115
|
+
...(0, import_language_common.composeNextState)(state, result),
|
|
116
|
+
result
|
|
117
|
+
};
|
|
118
|
+
if (callback)
|
|
119
|
+
callback(nextState);
|
|
120
|
+
return nextState;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
var defaultOpts = {
|
|
124
|
+
runAsync: true
|
|
125
|
+
};
|
|
126
|
+
async function execSql(statement, options) {
|
|
127
|
+
const opts = { ...defaultOpts, ...options };
|
|
128
|
+
const operation = await session.executeStatement(statement, opts);
|
|
129
|
+
await utils.waitUntilReady(operation, true);
|
|
130
|
+
await utils.fetchAll(operation);
|
|
131
|
+
const result = await utils.getResult(operation);
|
|
132
|
+
await operation.close();
|
|
133
|
+
return result.getValue();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/index.js
|
|
137
|
+
var src_default = Adaptor_exports;
|
|
138
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
139
|
+
0 && (module.exports = {
|
|
140
|
+
dataPath,
|
|
141
|
+
dataValue,
|
|
142
|
+
dateFns,
|
|
143
|
+
each,
|
|
144
|
+
execute,
|
|
145
|
+
field,
|
|
146
|
+
fields,
|
|
147
|
+
fn,
|
|
148
|
+
lastReferenceValue,
|
|
149
|
+
merge,
|
|
150
|
+
parseCsv,
|
|
151
|
+
query,
|
|
152
|
+
sourceValue
|
|
153
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/Adaptor.js
|
|
8
|
+
var Adaptor_exports = {};
|
|
9
|
+
__export(Adaptor_exports, {
|
|
10
|
+
dataPath: () => dataPath,
|
|
11
|
+
dataValue: () => dataValue,
|
|
12
|
+
dateFns: () => dateFns,
|
|
13
|
+
each: () => each,
|
|
14
|
+
execute: () => execute,
|
|
15
|
+
field: () => field,
|
|
16
|
+
fields: () => fields,
|
|
17
|
+
fn: () => fn,
|
|
18
|
+
lastReferenceValue: () => lastReferenceValue,
|
|
19
|
+
merge: () => merge,
|
|
20
|
+
parseCsv: () => parseCsv,
|
|
21
|
+
query: () => query,
|
|
22
|
+
sourceValue: () => sourceValue
|
|
23
|
+
});
|
|
24
|
+
import {
|
|
25
|
+
execute as commonExecute,
|
|
26
|
+
composeNextState
|
|
27
|
+
} from "@openfn/language-common";
|
|
28
|
+
import { expandReferences } from "@openfn/language-common/util";
|
|
29
|
+
import hive from "hive-driver";
|
|
30
|
+
import {
|
|
31
|
+
dataPath,
|
|
32
|
+
dataValue,
|
|
33
|
+
dateFns,
|
|
34
|
+
each,
|
|
35
|
+
field,
|
|
36
|
+
fields,
|
|
37
|
+
fn,
|
|
38
|
+
parseCsv,
|
|
39
|
+
lastReferenceValue,
|
|
40
|
+
merge,
|
|
41
|
+
sourceValue
|
|
42
|
+
} from "@openfn/language-common";
|
|
43
|
+
var { TCLIService, TCLIService_types } = hive.thrift;
|
|
44
|
+
var utils = new hive.HiveUtils(TCLIService_types);
|
|
45
|
+
var client = null;
|
|
46
|
+
var session = null;
|
|
47
|
+
var hiveClient = new hive.HiveClient(TCLIService, TCLIService_types);
|
|
48
|
+
var connection = new hive.connections.TcpConnection();
|
|
49
|
+
function execute(...operations) {
|
|
50
|
+
const initialState = {
|
|
51
|
+
references: [],
|
|
52
|
+
data: null
|
|
53
|
+
};
|
|
54
|
+
return (state) => {
|
|
55
|
+
return commonExecute(
|
|
56
|
+
connect,
|
|
57
|
+
...operations,
|
|
58
|
+
disconnect
|
|
59
|
+
)({
|
|
60
|
+
...initialState,
|
|
61
|
+
...state
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async function connect(state) {
|
|
66
|
+
const { host, port, username, password } = state.configuration;
|
|
67
|
+
const auth = username && password ? new hive.auth.PlainTcpAuthentication({
|
|
68
|
+
username,
|
|
69
|
+
password
|
|
70
|
+
}) : new hive.auth.NoSaslAuthentication();
|
|
71
|
+
client = await hiveClient.connect({ host, port }, connection, auth);
|
|
72
|
+
session = await client.openSession({
|
|
73
|
+
client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
|
|
74
|
+
});
|
|
75
|
+
console.log("Connect client");
|
|
76
|
+
return state;
|
|
77
|
+
}
|
|
78
|
+
async function disconnect(state) {
|
|
79
|
+
console.log("Disconnect client");
|
|
80
|
+
await session.close();
|
|
81
|
+
await client.close();
|
|
82
|
+
return state;
|
|
83
|
+
}
|
|
84
|
+
function query(qs, options, callback) {
|
|
85
|
+
return async (state) => {
|
|
86
|
+
const [resolvedQs, resolvedOptions] = expandReferences(state, qs, options);
|
|
87
|
+
console.log(`Executing query: ${resolvedQs}`);
|
|
88
|
+
const result = await execSql(resolvedQs, resolvedOptions);
|
|
89
|
+
console.log("Success... \u2714");
|
|
90
|
+
console.log("Retrieved", result.length, "items");
|
|
91
|
+
const nextState = {
|
|
92
|
+
...composeNextState(state, result),
|
|
93
|
+
result
|
|
94
|
+
};
|
|
95
|
+
if (callback)
|
|
96
|
+
callback(nextState);
|
|
97
|
+
return nextState;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
var defaultOpts = {
|
|
101
|
+
runAsync: true
|
|
102
|
+
};
|
|
103
|
+
async function execSql(statement, options) {
|
|
104
|
+
const opts = { ...defaultOpts, ...options };
|
|
105
|
+
const operation = await session.executeStatement(statement, opts);
|
|
106
|
+
await utils.waitUntilReady(operation, true);
|
|
107
|
+
await utils.fetchAll(operation);
|
|
108
|
+
const result = await utils.getResult(operation);
|
|
109
|
+
await operation.close();
|
|
110
|
+
return result.getValue();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/index.js
|
|
114
|
+
var src_default = Adaptor_exports;
|
|
115
|
+
export {
|
|
116
|
+
dataPath,
|
|
117
|
+
dataValue,
|
|
118
|
+
dateFns,
|
|
119
|
+
src_default as default,
|
|
120
|
+
each,
|
|
121
|
+
execute,
|
|
122
|
+
field,
|
|
123
|
+
fields,
|
|
124
|
+
fn,
|
|
125
|
+
lastReferenceValue,
|
|
126
|
+
merge,
|
|
127
|
+
parseCsv,
|
|
128
|
+
query,
|
|
129
|
+
sourceValue
|
|
130
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openfn/language-hive",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "An Apache HIVE adaptor for OpenFn",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"require": "./dist/index.cjs"
|
|
10
|
+
},
|
|
11
|
+
"./package.json": "./package.json"
|
|
12
|
+
},
|
|
13
|
+
"author": "Open Function Group",
|
|
14
|
+
"license": "LGPLv3",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"types/",
|
|
18
|
+
"ast.json",
|
|
19
|
+
"configuration-schema.json"
|
|
20
|
+
],
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@openfn/language-common": "^1.8.1",
|
|
23
|
+
"hive-driver": "0.2.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@openfn/buildtools": "^1.0.2",
|
|
27
|
+
"@openfn/simple-ast": "0.4.1",
|
|
28
|
+
"assertion-error": "2.0.0",
|
|
29
|
+
"chai": "4.3.6",
|
|
30
|
+
"deep-eql": "4.1.1",
|
|
31
|
+
"esno": "^0.16.3",
|
|
32
|
+
"mocha": "9.2.2",
|
|
33
|
+
"rimraf": "3.0.2"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/openfn/adaptors.git"
|
|
38
|
+
},
|
|
39
|
+
"types": "types/index.d.ts",
|
|
40
|
+
"main": "dist/index.cjs",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "pnpm clean && build-adaptor hive",
|
|
43
|
+
"test": "mocha --experimental-specifier-resolution=node --no-warnings",
|
|
44
|
+
"test:watch": "mocha -w --experimental-specifier-resolution=node --no-warnings",
|
|
45
|
+
"clean": "rimraf dist types docs",
|
|
46
|
+
"pack": "pnpm pack --pack-destination ../../dist",
|
|
47
|
+
"lint": "eslint src"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a sequence of operations.
|
|
3
|
+
* Wraps `language-common/execute` to make working with this API easier.
|
|
4
|
+
* @example
|
|
5
|
+
* execute(
|
|
6
|
+
* create('foo'),
|
|
7
|
+
* delete('bar')
|
|
8
|
+
* )(state)
|
|
9
|
+
* @private
|
|
10
|
+
* @param {Operations} operations - Operations to be performed.
|
|
11
|
+
* @returns {Operation}
|
|
12
|
+
*/
|
|
13
|
+
export function execute(...operations: Operations): Operation;
|
|
14
|
+
/**
|
|
15
|
+
* Execute an SQL statement
|
|
16
|
+
* @public
|
|
17
|
+
* @example
|
|
18
|
+
* <caption>Get patient count from hive database</caption>
|
|
19
|
+
* query("select count(*) from patient");
|
|
20
|
+
* @function
|
|
21
|
+
* @param {string} qs - SQL statement
|
|
22
|
+
* @param {object} options - (Optional) options for executing sql statement
|
|
23
|
+
* @param {function} callback - An optional callback function
|
|
24
|
+
* @returns {Operation}
|
|
25
|
+
*/
|
|
26
|
+
export function query(qs: string, options: object, callback: Function): Operation;
|
|
27
|
+
export { dataPath, dataValue, dateFns, each, field, fields, fn, parseCsv, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|
package/types/index.d.ts
ADDED