-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsc_script.py
48 lines (45 loc) · 1.55 KB
/
sc_script.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
import json
import string
def adapter_call(request):
root = json.loads(request)
if root["type"] == "createVirtualSchema":
return handleCreateVSchema(root)
elif root["type"] == "dropVirtualSchema":
return json.dumps({"type": "dropVirtualSchema"}).encode('utf-8')
elif root["type"] == "refresh":
return json.dumps({"type": "refresh"}).encode('utf-8')
elif root["type"] == "setProperties":
return json.dumps({"type": "setProperties"}).encode('utf-8')
if root["type"] == "getCapabilities":
return json.dumps({
"type": "getCapabilities",
"capabilities": []
}).encode('utf-8') # database expects utf-8 encoded string of type str. unicode not yet supported.
elif root["type"] == "pushdown":
return handlePushdown(root)
else:
raise ValueError('Unsupported callback')
def handleCreateVSchema(root):
res = {
"type": "createVirtualSchema",
"schemaMetadata": {
"tables": [
{
"name": "table_1",
"columns": [{
"name": "column_1",
"dataType": {"type": "VARCHAR", "size": 2000000}
},{
"name": "column_2",
"dataType": {"type": "VARCHAR", "size": 2000000}
}]
}]
}
}
return json.dumps(res).encode('utf-8')
def handlePushdown(root):
res = {
"type": "pushdown",
"sql": "select dummy from dual"
}
return json.dumps(res).encode('utf-8')