Skip to content

Commit d041721

Browse files
committed
[importer_direct_upload] supporting phoenix dialect for direct upload
1 parent 45221a6 commit d041721

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

desktop/core/src/desktop/js/ko/components/ko.historyPanel.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ class HistoryPanel {
189189
snippetImage: window.STATIC_URLS['impala/art/icon_impala_48.png'],
190190
sqlDialect: true
191191
},
192+
phoenix: {
193+
placeHolder: I18n('Example: SELECT * FROM tablename, or press CTRL + space'),
194+
aceMode: 'ace/mode/phoenix',
195+
snippetImage: window.STATIC_URLS['beeswax/art/icon_beeswax_48.png'],
196+
sqlDialect: true
197+
},
192198
java: {
193199
snippetIcon: 'fa-file-code-o'
194200
},

desktop/libs/indexer/src/indexer/indexers/sql.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,22 @@ def create_table_from_local_file(self, source, destination, start_time=-1):
313313
'columns': ',\n'.join([' `%(name)s` %(type)s' % col for col in columns]),
314314
}
315315

316+
elif dialect == 'phoenix':
317+
318+
for col in columns:
319+
if col['type'] == 'string':
320+
col['type'] = 'CHAR(255)'
321+
322+
sql = '''CREATE TABLE IF NOT EXISTS %(database)s.%(table_name)s (
323+
%(columns)s
324+
CONSTRAINT my_pk PRIMARY KEY (%(primary_keys)s));
325+
''' % {
326+
'database': database,
327+
'table_name': table_name,
328+
'columns': ',\n'.join([' %(name)s %(type)s' % col for col in columns]),
329+
'primary_keys': ', '.join(destination.get('indexerPrimaryKey'))
330+
}
331+
316332
path = urllib_unquote(source['path'])
317333

318334
if path: # data insertion
@@ -332,6 +348,17 @@ def create_table_from_local_file(self, source, destination, start_time=-1):
332348
'table_name': table_name,
333349
'csv_rows': csv_rows
334350
}
351+
if dialect == 'phoenix':
352+
for csv_row in list_of_tuples:
353+
_sql = ', '.join([ "'{0}'".format(col_val) if columns[count]['type'] in ('CHAR(255)', 'timestamp') \
354+
else '{0}'.format(col_val) for count, col_val in enumerate(csv_row)])
355+
356+
sql += '''\nUPSERT INTO %(database)s.%(table_name)s VALUES (%(csv_row)s);
357+
''' % {
358+
'database': database,
359+
'table_name': table_name,
360+
'csv_row': _sql
361+
}
335362

336363
on_success_url = reverse('metastore:describe_table', kwargs={'database': database, 'table': final_table_name}) + \
337364
'?source_type=' + source_type

desktop/libs/indexer/src/indexer/templates/importer.mako

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
554554
<label for="dialectType" class="control-label "><div>${ _('Dialect') }</div>
555555
<select id="dialectType" data-bind="selectize: $parent.createWizard.source.interpreters, value: $parent.createWizard.source.interpreter, optionsText: 'name', optionsValue: 'type'"></select>
556556
</label>
557+
<div data-bind="visible: dialect() == 'phoenix'">
558+
<label for="PhoenixPks" class="control-label"><div>${ _('Primary key') }</div>
559+
<select id="PhoenixPks" data-bind="selectize: columns, selectedOptions: indexerPrimaryKey, selectedObjects: indexerPrimaryKeyObject, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="1"></select>
560+
</label>
561+
</div>
557562
</div>
558563
<label for="collectionName" class="control-label "><div>${ _('Name') }</div></label>
559564
<input type="text" class="input-xxlarge" data-bind="value: name, hiveChooser: name, namespace: namespace, compute: compute, skipColumns: true, skipTables: outputFormat() == 'database', valueUpdate: 'afterkeydown', apiHelperUser: '${ user }', apiHelperType: sourceType, mainScrollable: $(MAIN_SCROLLABLE), attr: { 'placeholder': outputFormat() == 'table' ? '${ _ko('Table name or <database>.<table>') }' : '${ _ko('Database name') }' }" pattern="^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]*$" title="${ _('Only alphanumeric and underscore characters') }">
@@ -1800,6 +1805,11 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
18001805
self.interpreter.subscribe(function(val) {
18011806
self.sourceType(val);
18021807
wizard.destination.sourceType(val);
1808+
for (let i = 0; i < self.interpreters().length; i++) {
1809+
if (val == self.interpreters()[i]['type']) {
1810+
wizard.destination.dialect(self.interpreters()[i]['dialect']);
1811+
}
1812+
}
18031813
});
18041814
18051815
// File
@@ -2204,6 +2214,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
22042214
var self = this;
22052215
self.apiHelperType = vm.sourceType;
22062216
self.sourceType = ko.observable(vm.sourceType);
2217+
self.dialect = ko.observable('');
22072218
22082219
self.name = ko.observable('').extend({ throttle: 500 });
22092220
self.nameChanged = function(name) {

desktop/libs/notebook/src/notebook/connectors/sql_alchemy.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ def execute(self, notebook, snippet):
239239

240240
engine = self._get_engine()
241241
connection = self._create_connection(engine)
242-
statement = snippet['statement']
242+
stmt_dict = self._get_current_statement(notebook, snippet)
243+
statement = stmt_dict['statement']
243244

244245
if self.interpreter['dialect_properties'].get('trim_statement_semicolon', True):
245246
statement = statement.strip().rstrip(';')
@@ -270,7 +271,7 @@ def execute(self, notebook, snippet):
270271
}
271272
CONNECTIONS[guid] = cache
272273

273-
return {
274+
response = {
274275
'sync': False,
275276
'has_result_set': result.cursor != None,
276277
'modified_row_count': 0,
@@ -282,6 +283,9 @@ def execute(self, notebook, snippet):
282283
'type': 'table'
283284
}
284285
}
286+
response.update(stmt_dict)
287+
288+
return response
285289

286290

287291
@query_error_handler

0 commit comments

Comments
 (0)