importer.mako 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  1. ## Licensed to Cloudera, Inc. under one
  2. ## or more contributor license agreements. See the NOTICE file
  3. ## distributed with this work for additional information
  4. ## regarding copyright ownership. Cloudera, Inc. licenses this file
  5. ## to you under the Apache License, Version 2.0 (the
  6. ## "License"); you may not use this file except in compliance
  7. ## with the License. You may obtain a copy of the License at
  8. ##
  9. ## http://www.apache.org/licenses/LICENSE-2.0
  10. ##
  11. ## Unless required by applicable law or agreed to in writing, software
  12. ## distributed under the License is distributed on an "AS IS" BASIS,
  13. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ## See the License for the specific language governing permissions and
  15. ## limitations under the License.
  16. <%!
  17. from django.utils.translation import ugettext as _
  18. from desktop import conf
  19. from desktop.views import commonheader, commonfooter, commonshare, commonimportexport, _ko
  20. from indexer.conf import ENABLE_NEW_INDEXER
  21. %>
  22. <%namespace name="actionbar" file="actionbar.mako" />
  23. <%namespace name="assist" file="/assist.mako" />
  24. %if not is_embeddable:
  25. ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
  26. ## TODO lot of those re-imported
  27. <script src="${ static('desktop/js/autocomplete/sqlParseSupport.js') }"></script>
  28. <script src="${ static('desktop/js/autocomplete/sql.js') }"></script>
  29. <script src="${ static('desktop/js/sqlAutocompleter.js') }"></script>
  30. <script src="${ static('desktop/js/sqlAutocompleter2.js') }"></script>
  31. <script src="${ static('desktop/js/hdfsAutocompleter.js') }"></script>
  32. <script src="${ static('desktop/js/autocompleter.js') }"></script>
  33. <script src="${ static('desktop/js/hue.json.js') }"></script>
  34. <script src="${ static('desktop/js/jquery.hiveautocomplete.js') }" type="text/javascript" charset="utf-8"></script>
  35. <script src="${ static('desktop/ext/js/jquery/plugins/jquery-ui-1.10.4.custom.min.js') }"></script>
  36. <script src="${ static('desktop/ext/js/selectize.min.js') }"></script>
  37. <script src="${ static('metastore/js/metastore.ko.js') }"></script>
  38. <script src="${ static('desktop/js/ko.charts.js') }"></script>
  39. <script src="${ static('desktop/ext/js/knockout-sortable.min.js') }"></script>
  40. <script src="${ static('desktop/js/ko.editable.js') }"></script>
  41. <script src="${ static('desktop/ext/js/selectize.min.js') }"></script>
  42. <script src="${ static('desktop/js/ko.selectize.js') }"></script>
  43. ${ assist.assistJSModels() }
  44. <script src="${ static('notebook/js/notebook.ko.js') }"></script>
  45. <link rel="stylesheet" href="${ static('notebook/css/notebook.css') }">
  46. <link rel="stylesheet" href="${ static('notebook/css/notebook-layout.css') }">
  47. ${ assist.assistPanel() }
  48. <link rel="stylesheet" href="${ static('desktop/ext/css/selectize.css') }">
  49. %endif
  50. <link rel="stylesheet" href="${ static('desktop/css/wizard.css') }">
  51. <style type="text/css">
  52. % if conf.CUSTOM.BANNER_TOP_HTML.get():
  53. .show-assist {
  54. top: 110px!important;
  55. }
  56. .main-content {
  57. top: 112px!important;
  58. }
  59. % endif
  60. .path {
  61. margin-bottom: 0!important;
  62. border-right: none!important;
  63. }
  64. .step .card-heading.simple {
  65. font-size: 17px;
  66. }
  67. .step .card-body {
  68. margin-top: 14px;
  69. }
  70. .step label > div:first-child {
  71. width: 120px;
  72. text-align: right;
  73. padding-right: 8px;
  74. display: inline-block;
  75. vertical-align: top;
  76. padding-top: 6px;
  77. }
  78. .step label.checkbox {
  79. margin-left: 130px;
  80. }
  81. .step .index-field label.checkbox {
  82. margin-left: 5px;
  83. }
  84. .step .index-field label > div:first-child {
  85. width: initial;
  86. }
  87. .step .field-properties label.checkbox {
  88. margin-left: 10px;
  89. }
  90. .step label:not(.checkbox) {
  91. display: inline-block;
  92. vertical-align: middle;
  93. }
  94. .step input[type='text'] {
  95. margin-bottom: 0;
  96. }
  97. .step .selectize-control {
  98. display: inline-block;
  99. vertical-align: middle;
  100. width: 578px !important;
  101. }
  102. .step .form-inline .selectize-control {
  103. width: 120px !important;
  104. margin-bottom: -8px;
  105. }
  106. .step .inline-labels {
  107. display: table;
  108. }
  109. .step .inline-labels .selectize-control {
  110. width: 120px !important;
  111. vertical-align: -12px;
  112. }
  113. .step .selectize-input {
  114. max-height: 31px;
  115. }
  116. .step .selectize-control.multi .selectize-input {
  117. padding-top: 3px!important;
  118. }
  119. .step .show-edit-on-hover a {
  120. opacity: 0;
  121. -webkit-transition: opacity 0.2s linear;
  122. -moz-transition: opacity 0.2s linear;
  123. -ms-transition: opacity 0.2s linear;
  124. -o-transition: opacity 0.2s linear;
  125. transition: opacity 0.2s linear;
  126. }
  127. .step .show-edit-on-hover:hover a {
  128. opacity: 1;
  129. }
  130. .step .show-edit-on-hover .inactive-action {
  131. margin-left: 6px;
  132. vertical-align: middle;
  133. }
  134. .step .fa-padding-top {
  135. padding-top: 8px;
  136. }
  137. .kudu-partitions li {
  138. width: 578px !important;
  139. padding: 5px;
  140. }
  141. .kudu-partitions li:hover {
  142. background-color: #F7F7F7;
  143. }
  144. .kudu-partitions .range-partition {
  145. padding: 5px;
  146. }
  147. .kudu-partitions .range-partition:hover {
  148. background-color: #F1F1F1;
  149. }
  150. .step .kudu-partitions li .selectize-control {
  151. width: 100px !important;
  152. vertical-align: top;
  153. }
  154. .field {
  155. padding: 4px;
  156. padding-left: 10px;
  157. border-left: 4px solid #DBE8F1;
  158. }
  159. .operation {
  160. border-left: 4px solid #EEE;
  161. padding-left: 10px;
  162. margin-top: 5px;
  163. margin-bottom: 5px;
  164. margin-left: 10px;
  165. }
  166. .field-content-preview {
  167. width: 180px;
  168. margin-left: 20px;
  169. }
  170. .table-preview {
  171. margin:auto;
  172. text-align:left;
  173. }
  174. .table-preview td, .table-preview th {
  175. white-space: nowrap;
  176. }
  177. .content-panel {
  178. overflow-x: hidden;
  179. }
  180. .content-panel-inner {
  181. margin: 10px;
  182. margin-bottom: 100px;
  183. }
  184. .form-control.path {
  185. vertical-align: top;
  186. }
  187. .form-actions {
  188. position: fixed;
  189. bottom: 0;
  190. margin: 0;
  191. z-index: 1000;
  192. border-top: 1px solid #e5e5e5;
  193. }
  194. #importerNotebook {
  195. height: 5px;
  196. float: right;
  197. }
  198. #importerNotebook .snippet-error-container {
  199. background: transparent;
  200. }
  201. .inline-table {
  202. display: inline-table;
  203. }
  204. .columns-form {
  205. margin-bottom: 200px;
  206. }
  207. </style>
  208. <span id="importerComponents" class="notebook" data-bind="dropzone: { url: '/filebrowser/upload/file?dest=' + DropzoneGlobals.homeDir, params: {dest: DropzoneGlobals.homeDir}, paramName: 'hdfs_file', onComplete: function(path){ createWizard.source.path(path); } }">
  209. <div class="dz-message" data-dz-message></div>
  210. <div class="navbar hue-title-bar">
  211. <div class="navbar-inner">
  212. <div class="container-fluid">
  213. <div class="nav-collapse">
  214. <ul class="nav">
  215. <li class="app-header">
  216. <a href="${ url('indexer:importer') }">
  217. <i class="fa fa-database app-icon"></i> ${_('Importer')}</a>
  218. </a>
  219. </li>
  220. </ul>
  221. </div>
  222. </div>
  223. </div>
  224. </div>
  225. %if not is_embeddable:
  226. <a title="${_('Toggle Assist')}" class="pointer show-assist" data-bind="visible: !$root.isLeftPanelVisible() && $root.assistAvailable(), click: function() { $root.isLeftPanelVisible(true); }">
  227. <i class="fa fa-chevron-right"></i>
  228. </a>
  229. %endif
  230. <div class="main-content">
  231. <div class="vertical-full container-fluid" data-bind="style: { 'padding-left' : $root.isLeftPanelVisible() ? '0' : '20px' }">
  232. <div class="vertical-full">
  233. <div class="vertical-full row-fluid panel-container">
  234. %if not is_embeddable:
  235. <div class="assist-container left-panel" data-bind="visible: $root.isLeftPanelVisible() && $root.assistAvailable()">
  236. <a title="${_('Toggle Assist')}" class="pointer hide-assist" data-bind="click: function() { $root.isLeftPanelVisible(false) }">
  237. <i class="fa fa-chevron-left"></i>
  238. </a>
  239. <div class="assist" data-bind="component: {
  240. name: 'assist-panel',
  241. params: {
  242. user: '${user.username}',
  243. onlySql: false,
  244. sql: {
  245. navigationSettings: {
  246. openItem: false,
  247. showStats: true
  248. }
  249. },
  250. visibleAssistPanels: ['sql', 'hdfs', 'documents']
  251. }
  252. }"></div>
  253. </div>
  254. <div class="resizer" data-bind="visible: $root.isLeftPanelVisible() && $root.assistAvailable(), splitDraggable : { appName: 'notebook', leftPanelVisible: $root.isLeftPanelVisible }"><div class="resize-bar">&nbsp;</div></div>
  255. %endif
  256. <div class="content-panel">
  257. <div class="content-panel-inner">
  258. <!-- ko template: 'create-index-wizard' --><!-- /ko -->
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. </div>
  264. </div>
  265. <div id="chooseFile" class="modal hide fade">
  266. <div class="modal-header">
  267. <button type="button" class="close" data-dismiss="modal" aria-label="${ _('Close') }"><span aria-hidden="true">&times;</span></button>
  268. <h2 class="modal-title">${_('Choose a file')}</h2>
  269. </div>
  270. <div class="modal-body">
  271. <div id="filechooser"></div>
  272. </div>
  273. <div class="modal-footer"></div>
  274. </div>
  275. <script type="text/html" id="create-index-wizard">
  276. <div data-bind="visible: createWizard.show">
  277. <div class="step-indicator-fixed">
  278. <ol class="list-inline text-center step-indicator">
  279. <li data-bind="css: { 'active': currentStep() == 1, 'complete': currentStep() > 1, 'pointer': currentStep() > 1 }, click: function() { currentStep(1) }">
  280. <div class="step" title="${ _('Go to Step 1') }">
  281. <!-- ko if: currentStep() == 1 -->
  282. <!-- ko if: createWizard.isGuessingFormat -->
  283. <span class="fa fa-spinner fa-spin"></span>
  284. <!-- /ko -->
  285. <!-- ko ifnot: createWizard.isGuessingFormat -->
  286. 1
  287. <!-- /ko -->
  288. <!-- /ko -->
  289. <!-- ko ifnot: currentStep() == 1 -->
  290. <span class="fa fa-check"></span>
  291. <!-- /ko -->
  292. </div>
  293. <div class="caption">
  294. <!-- ko if: createWizard.source.inputFormat() != 'manual' -->
  295. ${ _('Pick data from ') }<span data-bind="text: createWizard.source.inputFormat"></span> <span data-bind="text: createWizard.source.path"></span>
  296. <!-- /ko -->
  297. <!-- ko if: createWizard.source.inputFormat() == 'manual' -->
  298. ${ _('No source data') }
  299. <!-- /ko -->
  300. </div>
  301. </li>
  302. <li data-bind="css: { 'inactive': currentStep() == 1, 'active': currentStep() == 2, 'complete': currentStep() == 3, 'pointer': currentStep() == 1 && !createWizard.isGuessingFormat() && createWizard.source.show() }, click: function() { if (!createWizard.isGuessingFormat() && createWizard.source.show()){ currentStep(2); }}">
  303. <div class="step" title="${ _('Go to Step 2') }">
  304. <!-- ko if: currentStep() < 3 -->
  305. <!-- ko if: createWizard.isGuessingFieldTypes -->
  306. <span class="fa fa-spinner fa-spin"></span>
  307. <!-- /ko -->
  308. <!-- ko ifnot: createWizard.isGuessingFieldTypes -->
  309. 2
  310. <!-- /ko -->
  311. <!-- /ko -->
  312. </div>
  313. <div class="caption">
  314. <!-- ko if: createWizard.source.inputFormat() != 'manual' -->
  315. ${ _('Move it to ') }
  316. <!-- /ko -->
  317. <!-- ko if: createWizard.source.inputFormat() == 'manual' -->
  318. ${ _('Create') }
  319. <!-- /ko -->
  320. <span data-bind="text: createWizard.destination.outputFormat"></span> <span data-bind="text: createWizard.destination.name"></span>
  321. </div>
  322. </li>
  323. </ol>
  324. </div>
  325. <div class="vertical-spacer"></div>
  326. <!-- ko if: currentStep() == 1 -->
  327. <div class="card step">
  328. <h3 class="card-heading simple">${_('Source')}</h3>
  329. <div class="card-body">
  330. <div>
  331. <div class="control-group" data-bind="visible: createWizard.prefill.target_type().length == 0 || createWizard.prefill.source_type() == 'all'">
  332. <label for="sourceType" class="control-label"><div>${ _('Type') }</div>
  333. <select id="sourceType" data-bind="selectize: createWizard.source.inputFormats, value: createWizard.source.inputFormat, optionsText: 'name', optionsValue: 'value'"></select>
  334. </label>
  335. </div>
  336. <div class="control-group" data-bind="visible: createWizard.prefill.target_type() == 'database'">
  337. <label for="sourceType" class="control-label">${ _('No source is needed for creating a database.') }</label>
  338. </div>
  339. <div class="control-group input-append" data-bind="visible: createWizard.source.inputFormat() == 'file'">
  340. <label for="path" class="control-label"><div>${ _('Path') }</div>
  341. <input type="text" class="form-control path input-xxlarge" data-bind="value: createWizard.source.path, filechooser: createWizard.source.path, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true, openOnFocus: true, selectFolder: false }" placeholder="${ _('Click or drag from the assist') }">
  342. </label>
  343. <!-- ko if: createWizard.source.path().length > 0 -->
  344. <a data-bind="hueLink: '/filebrowser/view=' + createWizard.source.path()" title="${ _('Open') }" style="font-size: 14px" class="margin-left-10">
  345. <i class="fa fa-external-link-square"></i>
  346. </a>
  347. <!-- /ko -->
  348. </div>
  349. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'table'">
  350. <label for="path" class="control-label"><div>${ _('Table') }</div>
  351. <input type="text" class="input-xlarge" data-bind="value: createWizard.source.table, hivechooser: createWizard.source.table, skipColumns: true, apiHelperUser: '${ user }', apiHelperType: createWizard.source.apiHelperType, mainScrollable: $('.content-panel')" placeholder="${ _('Table name or <database>.<table>') }">
  352. </label>
  353. </div>
  354. <div class="control-group" data-bind="visible: createWizard.source.inputFormat() == 'query'">
  355. <label for="path" class="control-label"><div>${ _('Query') }</div>
  356. <select placeholder="${ _('Search your documents...') }" data-bind="documentChooser: { dependentValue: createWizard.source.draggedQuery, mappedDocument: createWizard.source.query }"></select>
  357. </label>
  358. </div>
  359. </div>
  360. </div>
  361. </div>
  362. <!-- ko if: createWizard.source.show() && createWizard.source.inputFormat() != 'manual' -->
  363. <div class="card step">
  364. <!-- ko if: createWizard.isGuessingFormat -->
  365. <h3 class="card-heading simple">${_('Guessing format...')} <i class="fa fa-spinner fa-spin"></i></h3>
  366. <!-- /ko -->
  367. <!-- ko ifnot: createWizard.isGuessingFormat -->
  368. <h3 class="card-heading simple">${_('Format')}</h3>
  369. <div class="card-body">
  370. <label data-bind="visible: createWizard.prefill.source_type().length == 0 && createWizard.source.inputFormat() != 'table'">
  371. <div>${_('File Type')}</div>
  372. <select data-bind="selectize: $root.createWizard.fileTypes, value: $root.createWizard.fileTypeName, optionsText: 'description', optionsValue: 'name'"></select>
  373. </label>
  374. <span class="inline-labels" data-bind="with: createWizard.source.format, visible: createWizard.source.show">
  375. <span data-bind="foreach: getArguments()">
  376. <!-- ko template: {name: 'arg-' + $data.type, data: {description: $data.description, value: $parent[$data.name]}}--><!-- /ko -->
  377. </span>
  378. </span>
  379. </div>
  380. <!-- /ko -->
  381. </div>
  382. <div class="card step" style="min-height: 310px;">
  383. <!-- ko ifnot: createWizard.isGuessingFormat -->
  384. <!-- ko if: createWizard.isGuessingFieldTypes -->
  385. <h3 class="card-heading simple">${_('Generating preview...')} <i class="fa fa-spinner fa-spin"></i></h3>
  386. <!-- /ko -->
  387. <!-- ko ifnot: createWizard.isGuessingFieldTypes -->
  388. <h3 class="card-heading simple">${_('Preview')}</h3>
  389. <div class="card-body">
  390. <div style="overflow: auto">
  391. <table class="table table-condensed table-preview">
  392. <thead>
  393. <tr data-bind="foreach: createWizard.source.sampleCols">
  394. ##<!-- ko template: 'field-preview-header-template' --><!-- /ko -->
  395. <th data-bind="truncatedText: name" style="padding-right:60px"></th>
  396. ## TODO nested
  397. </tr>
  398. </thead>
  399. <tbody data-bind="foreach: createWizard.source.sample">
  400. <tr data-bind="foreach: $data">
  401. ##<!-- ko if: $index() < $root.createWizard.source.columns().length -->
  402. ##<td data-bind="visible: $root.createWizard.source.columns()[$index()].keep, text: $data"></td>
  403. <td data-bind="truncatedText: $data"></td>
  404. ##<!-- ko with: $root.createWizard.source.columns()[$index()] -->
  405. ## <!-- ko template: 'output-generated-field-data-template' --> <!-- /ko -->
  406. ##<!-- /ko -->
  407. ##<!-- /ko -->
  408. </tr>
  409. </tbody>
  410. </table>
  411. </div>
  412. </div>
  413. <!-- /ko -->
  414. <!-- /ko -->
  415. </div>
  416. <!-- /ko -->
  417. <!-- /ko -->
  418. <!-- ko if: currentStep() == 2 -->
  419. <!-- ko with: createWizard.destination -->
  420. <div class="card step">
  421. <h3 class="card-heading simple">${_('Destination')}</h3>
  422. <div class="card-body">
  423. <div class="control-group">
  424. <label for="destinationType" class="control-label" data-bind="visible: $parent.createWizard.prefill.target_type().length == 0"><div>${ _('Type') }</div>
  425. <select id="destinationType" data-bind="selectize: outputFormats, value: outputFormat, optionsValue: 'value', optionsText: 'name'"></select>
  426. </label>
  427. </div>
  428. <div class="control-group">
  429. <label for="collectionName" class="control-label "><div>${ _('Name') }</div></label>
  430. <!-- ko if: outputFormat() != 'table' && outputFormat() != 'database' -->
  431. <input type="text" class="form-control input-xlarge" id="collectionName" data-bind="value: name, valueUpdate: 'afterkeydown'" placeholder="${ _('Name') }">
  432. <!-- /ko -->
  433. <!-- ko if: outputFormat() == 'table' || outputFormat() == 'database' -->
  434. <input type="text" data-bind="value: name, hivechooser: name, skipColumns: true, skipTables: outputFormat() == 'database', valueUpdate: 'afterkeydown', apiHelperUser: '${ user }', apiHelperType: apiHelperType, mainScrollable: $('.content-panel'), 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') }">
  435. <!-- /ko -->
  436. <span class="help-inline muted" data-bind="visible: !isTargetExisting() && isTargetChecking()">
  437. <i class="fa fa-spinner fa-spin"></i>
  438. </span>
  439. <span class="help-inline muted" data-bind="visible: ! $parent.createWizard.isValidDestination()">
  440. <i class="fa fa-warning" style="color: #c09853"></i> ${ _('Invalid characters') }
  441. </span>
  442. <span class="help-inline muted" data-bind="visible: isTargetExisting()">
  443. <!-- ko if: outputFormat() == 'index' -->
  444. ${ _('Adding data to the existing ') } <span data-bind="text: outputFormat"></span>
  445. <!-- /ko -->
  446. <!-- ko if: outputFormat() != 'index' -->
  447. <i class="fa fa-warning" style="color: #c09853"></i> ${ _('Already existing') } <span data-bind="text: outputFormat"></span>
  448. <!-- /ko -->
  449. <a href="javascript:void(0)" data-bind="hueLink: existingTargetUrl(), text: name" target="_blank" title="${ _('Open') }"></a>
  450. </span>
  451. </div>
  452. </div>
  453. </div>
  454. <!-- ko if: outputFormat() == 'table' -->
  455. <div class="card step">
  456. <h3 class="card-heading simple">${_('Properties')}</h3>
  457. <div class="card-body">
  458. <div class="control-group">
  459. <label for="destinationFormat" class="control-label"><div>${ _('Format') }</div>
  460. <select id="destinationFormat" data-bind="selectize: tableFormats, value: tableFormat, optionsValue: 'value', optionsText: 'name'"></select>
  461. </label>
  462. </div>
  463. <div class="control-group">
  464. <label class="checkbox inline-block" data-bind="visible: tableFormat() != 'kudu'">
  465. <input type="checkbox" data-bind="checked: useDefaultLocation"> ${_('Store in Default location')}
  466. </label>
  467. </div>
  468. <div class="control-group" data-bind="visible: ! useDefaultLocation()">
  469. <label for="path" class="control-label"><div>${ _('External location') }</div>
  470. <input type="text" class="form-control path input-xxlarge" data-bind="value: nonDefaultLocation, filechooser: nonDefaultLocation, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true }, valueUpdate: 'afterkeydown'">
  471. </label>
  472. </div>
  473. <div class="control-group">
  474. <label class="control-label"><div>${ _('Extras') }</div>
  475. <a href="javascript:void(0)" data-bind="css: { 'inactive-action': !showProperties() }, click: function() { showProperties(!showProperties()) }" title="${ _('Show extra properties') }">
  476. <i class="fa fa-sliders fa-padding-top"></i>
  477. </a>
  478. </label>
  479. </div>
  480. <span data-bind="visible: showProperties">
  481. <div class="control-group">
  482. <label class="checkbox inline-block" data-bind="visible: $root.createWizard.source.inputFormat() != 'manual'">
  483. <input type="checkbox" data-bind="checked: importData, disable: ! useDefaultLocation() && $parent.createWizard.source.path() == nonDefaultLocation();"> ${_('Import data')}
  484. </label>
  485. </div>
  486. <div class="control-group">
  487. <label><div>${ _('Description') }</div>
  488. <input type="text" class="form-control input-xxlarge" data-bind="value: description, valueUpdate: 'afterkeydown'" placeholder="${ _('Description') }">
  489. </label>
  490. </div>
  491. <div class="control-group" data-bind="visible: $root.createWizard.source.inputFormat() == 'file'">
  492. <label class="checkbox inline-block">
  493. <input type="checkbox" data-bind="checked: hasHeader"> ${_('Use first row as header')}
  494. </label>
  495. </div>
  496. <div class="control-group" data-bind="visible: tableFormat() == 'text'">
  497. <label class="checkbox inline-block">
  498. <input type="checkbox" data-bind="checked: useCustomDelimiters"> ${_('Custom char delimiters')}
  499. </label>
  500. </div>
  501. <span class="inline-labels" data-bind="visible: tableFormat() == 'text' && useCustomDelimiters()">
  502. <label for="fieldDelimiter" class="control-label"><div>${ _('Field') }</div>
  503. <select id="fieldDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: customFieldDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  504. </label>
  505. <label for="collectionDelimiter" class="control-label"><div>${ _('Array, Map') }</div>
  506. <select id="collectionDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: customCollectionDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  507. </label>
  508. <label for="structDelimiter" class="control-label"><div>${ _('Struct') }</div>
  509. <select id="structDelimiter" data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: customMapDelimiter, optionsValue: 'value', optionsText: 'name'"></select>
  510. </label>
  511. </span>
  512. </span>
  513. <div class="control-group" data-bind="visible: tableFormat() == 'regexp'">
  514. <label for="customRegexp" class="control-label"><div>${ _('Regexp') }</div>
  515. <input id="customRegexp" class="input-xxlarge" type="text" data-bind="value: customRegexp" placeholder='([^]*) ([^]*) ([^]*) (-|\\[^\\]*\\]) ([^ \"]*|\"[^\"]*\") (-|[0-9]*) (-|[0-9]*)(?: ([^ \"]*|\".*\") ([^ \"]*|\".*\"))?'>
  516. </label>
  517. </div>
  518. <div class="control-group" data-bind="visible: tableFormat() == 'kudu'">
  519. <label for="kuduPks" class="control-label"><div>${ _('Primary keys') }</div>
  520. ## At least one selected
  521. <select id="kuduPks" data-bind="selectize: columns, selectedOptions: primaryKeys, selectedObjects: primaryKeyObjects, optionsValue: 'name', optionsText: 'name', innerSubscriber: 'name'" size="3" multiple="true"></select>
  522. </label>
  523. </div>
  524. <label class="control-label"><div>${ _('Partitions') }</div>
  525. <!-- ko if: tableFormat() != 'kudu' -->
  526. <div class="inline-table">
  527. <div class="form-inline" data-bind="foreach: partitionColumns">
  528. <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.partitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
  529. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  530. <div class="clearfix"></div>
  531. </div>
  532. <a data-bind="click: function() { partitionColumns.push($root.loadDefaultField({isPartition: true})); }" class="pointer" title="${_('Add Partition')}"><i class="fa fa-plus fa-padding-top"></i> ${_('Add partition')}</a>
  533. </div>
  534. <!-- /ko -->
  535. <!-- ko if: tableFormat() == 'kudu' -->
  536. <div class="form-inline inline-table">
  537. <ul class="unstyled kudu-partitions" data-bind="foreach: kuduPartitionColumns">
  538. <li>
  539. <a class="pointer pull-right" data-bind="click: function() { $parent.kuduPartitionColumns.remove($data); }"><i class="fa fa-minus"></i></a>
  540. <select data-bind="selectize: $parent.primaryKeyObjects, selectedOptions: columns, optionsValue: 'name', optionsText: 'name', selectizeOptions: { placeholder: '${ _ko('Columns...') }' }" size="3" multiple="true"></select>
  541. <select data-bind="selectize: ['RANGE BY', 'HASH'], value: name"></select>
  542. <!-- ko if: name() == 'HASH' -->
  543. <input class="input-small" type="number" data-bind="value: int_val">
  544. <!-- /ko -->
  545. <!-- ko if: name() == 'RANGE BY' -->
  546. <div class="form-inline" data-bind="foreach: range_partitions">
  547. <div class="range-partition">
  548. <a class="pull-right" data-bind="click: function() { $parent.range_partitions.remove($data); }"><i class="fa fa-minus"></i></a>
  549. <!-- ko if: name() == 'VALUES' -->
  550. <input type="text" class="input-small" data-bind="value: lower_val">
  551. <select data-bind="selectize: ['<', '<='], value: include_lower_val"></select>
  552. <select data-bind="selectize: ['VALUES', 'VALUE'], value: name"></select>
  553. <select data-bind="selectize: ['<', '<='], value: include_upper_val"></select>
  554. <input type="text" class="input-small" data-bind="value: upper_val">
  555. <!-- /ko -->
  556. <!-- ko if: name() == 'VALUE' -->
  557. <select data-bind="selectize: ['VALUES', 'VALUE'], value: name"></select>
  558. <div class="inline-block" data-bind="foreach: values" style="max-width: 370px">
  559. <input class="input-small" type="text" data-bind="textInput: value" style="margin-bottom: 5px">
  560. <a data-bind="click: function() { $parent.values.remove($data); }"><i class="fa fa-minus"></i></a>
  561. </div>
  562. <a class="inline-block" data-bind="click: function() { values.push(ko.mapping.fromJS({value: ''})); }" title="${_('Add value')}"><i class="fa fa-plus"></i></a>
  563. <div class="clearfix"></div>
  564. <!-- /ko -->
  565. </div>
  566. </div>
  567. <a data-bind="click: function() { range_partitions.push(ko.mapping.fromJS($parent.KUDU_DEFAULT_RANGE_PARTITION_COLUMN)); }" title="${_('Add column')}"><i class="fa fa-plus"></i></a>
  568. <!-- /ko -->
  569. <!-- /ko -->
  570. </li>
  571. </ul>
  572. <a data-bind="click: function() { kuduPartitionColumns.push(ko.mapping.fromJS(KUDU_DEFAULT_PARTITION_COLUMN)); }" class="pointer" title="${_('Add partition')}"><i class="fa fa-plus"></i> ${_('Add partition')}</a>
  573. </div>
  574. <!-- /ko -->
  575. </label>
  576. </div>
  577. </div>
  578. <!-- /ko -->
  579. <!-- ko if: outputFormat() == 'table' || outputFormat() == 'index' -->
  580. <div class="card step">
  581. <h3 class="card-heading simple show-edit-on-hover">${_('Fields')} <!-- ko if: $root.createWizard.isGuessingFieldTypes --><i class="fa fa-spinner fa-spin"></i><!-- /ko --> <a class="inactive-action pointer" data-bind="visible: columns().length > 0" href="#fieldsBulkEditor" data-toggle="modal"><i class="fa fa-edit"></i></a></h3>
  582. <div class="card-body no-margin-top columns-form">
  583. <!-- ko if: $root.createWizard.source.inputFormat() === 'manual' -->
  584. <form class="form-inline inline-table" data-bind="foreach: columns">
  585. <!-- ko if: $parent.outputFormat() == 'table' -->
  586. <a class="pointer pull-right margin-top-20" data-bind="click: function() { $parent.columns.remove($data); }"><i class="fa fa-minus"></i></a>
  587. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  588. <div class="clearfix"></div>
  589. <!-- /ko -->
  590. <!-- ko if: $parent.outputFormat() == 'index' -->
  591. <div data-bind="template: { name: 'index-field-template', data: $data }" class="margin-top-10 field inline-block index-field"></div>
  592. <div class="clearfix"></div>
  593. <!-- /ko -->
  594. </form>
  595. <div class="clearfix"></div>
  596. <!-- ko if: outputFormat() == 'table' -->
  597. <a data-bind="click: function() { columns.push($root.loadDefaultField({})); }" class="pointer" title="${_('Add Field')}"><i class="fa fa-plus"></i> ${_('Add Field')}</a>
  598. <!-- /ko -->
  599. <!-- /ko -->
  600. <!-- ko ifnot: $root.createWizard.source.inputFormat() === 'manual' -->
  601. <form class="form-inline inline-table" data-bind="foreachVisible: { data: columns, minHeight: 44, container: '.content-panel', disableNiceScroll: true }">
  602. <!-- ko if: $parent.outputFormat() == 'table' -->
  603. <div data-bind="template: { name: 'table-field-template', data: $data }" class="margin-top-10 field inline-block"></div>
  604. <div class="clearfix"></div>
  605. <!-- /ko -->
  606. <!-- ko if: $parent.outputFormat() == 'index' -->
  607. <div data-bind="template: { name: 'index-field-template', data: $data }" class="margin-top-10 field inline-block index-field"></div>
  608. <div class="clearfix"></div>
  609. <!-- /ko -->
  610. </form>
  611. <div class="clearfix"></div>
  612. <!-- /ko -->
  613. </div>
  614. </div>
  615. <!-- /ko -->
  616. <!-- ko if: outputFormat() == 'database' -->
  617. <div class="card step">
  618. <h3 class="card-heading simple">${_('Properties')}</h3>
  619. <div class="card-body">
  620. <label><div>${ _('Description') }</div>
  621. <input type="text" class="form-control input-xlarge" data-bind="value: description, valueUpdate: 'afterkeydown'" placeholder="${ _('Description') }">
  622. </label>
  623. <label class="checkbox">
  624. <input type="checkbox" data-bind="checked: useDefaultLocation"> ${_('Default location')}
  625. </label>
  626. <span data-bind="visible: ! useDefaultLocation()">
  627. <label for="path" class="control-label"><div>${ _('External location') }</div>
  628. <input type="text" class="form-control path input-xxlarge" data-bind="value: nonDefaultLocation, filechooser: nonDefaultLocation, filechooserOptions: { linkMarkup: true, skipInitialPathIfEmpty: true }, valueUpdate: 'afterkeydown'">
  629. </label>
  630. </span>
  631. </div>
  632. </div>
  633. <!-- /ko -->
  634. <!-- /ko -->
  635. <!-- /ko -->
  636. <div class="form-actions">
  637. <!-- ko if: previousStepVisible -->
  638. <button class="btn" data-bind="click: previousStep">${ _('Back') }</button>
  639. <!-- /ko -->
  640. <!-- ko if: currentStep() == 1 -->
  641. <button class="btn" data-bind="enable: !createWizard.isGuessingFormat() && createWizard.source.show(), click: function() { currentStep(2); }">
  642. ${_('Next')}
  643. </button>
  644. <!-- /ko -->
  645. <!-- ko if: currentStep() == 2 -->
  646. <button class="btn btn-primary disable-feedback" data-bind="click: createWizard.indexFile, enable: createWizard.readyToIndex() && ! createWizard.indexingStarted()">
  647. ${ _('Submit') } <i class="fa fa-spinner fa-spin" data-bind="visible: createWizard.indexingStarted"></i>
  648. </button>
  649. <!-- /ko -->
  650. <span data-bind="visible: createWizard.editorId">
  651. <button class="btn btn-success" data-bind="click: function(){ window.open('${ url('notebook:editor') }?editor=' + createWizard.editorId()) }" title="${ _('Open') }">
  652. ${_('Check status')}
  653. </button>
  654. </span>
  655. <div id="importerNotebook"></div>
  656. </div>
  657. </div>
  658. <div id="fieldsBulkEditor" class="modal hide fade">
  659. <div class="modal-header">
  660. <button type="button" class="close" data-dismiss="modal" aria-label="${ _('Close') }"><span aria-hidden="true">&times;</span></button>
  661. <h2 class="modal-title">${ _('Write or paste comma separated field names') }</h2>
  662. </div>
  663. <div class="modal-body">
  664. <input type="text" class="input-xxlarge" placeholder="${ _('e.g. id, name, salary') }" data-bind="textInput: createWizard.destination.bulkColumnNames">
  665. </div>
  666. <div class="modal-footer">
  667. <button class="btn" data-dismiss="modal" aria-hidden="true">${ _('Cancel') }</button>
  668. <button class="btn btn-primary" data-bind="click: createWizard.destination.processBulkColumnNames">${ _('Change field names') }</button>
  669. </div>
  670. </div>
  671. </script>
  672. <script type="text/html" id="table-field-template">
  673. <div>
  674. <label data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">${ _('Name') }&nbsp;
  675. <input type="text" class="input-large" placeholder="${ _('Field name') }" required data-bind="textInput: name">
  676. </label>
  677. <label class="margin-left-5">${ _('Type') }&nbsp;
  678. <!-- ko if: ! (level() > 0 && $parent.type() == 'map') -->
  679. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.hiveFieldTypes, value: type"></select>
  680. <!-- /ko -->
  681. <!-- ko if: level() > 0 && $parent.type() == 'map' -->
  682. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.hivePrimitiveFieldTypes, value: keyType"></select>
  683. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.hiveFieldTypes, value: type"></select>
  684. <!-- /ko -->
  685. <input type="number" class="input-small" placeholder="${ _('Length') }" data-bind="value: length, visible: type() == 'varchar' || type() == 'char'">
  686. <!-- ko if: $parent.type() == 'decimal' -->
  687. <input type="number" class="input-small" placeholder="${ _('Precision') }" data-bind="value: precision">
  688. <input type="number" class="input-small" placeholder="${ _('Scale') }" data-bind="value: scale">
  689. <!-- /ko -->
  690. </label>
  691. <!-- ko if: $root.createWizard.source.inputFormat() != 'manual' && typeof isPartition !== 'undefined' && isPartition() -->
  692. <label class="margin-left-5">${ _('Value') }&nbsp;
  693. <input type="text" class="input-medium margin-left-5" placeholder="${ _('Partition value') }" data-bind="value: partitionValue">
  694. </label>
  695. <!-- /ko -->
  696. <span data-bind="visible: level() == 0 || ($parent.type() != 'array' && $parent.type() != 'map')">
  697. <a href="javascript:void(0)" title="${ _('Show field properties') }" data-bind="css: {'inactive-action': !showProperties()}, click: function() {showProperties(!showProperties()) }"><i class="fa fa-sliders"></i></a>
  698. <span data-bind="visible: showProperties">
  699. <input type="text" class="input-medium margin-left-5" placeholder="${ _('Field comment') }" data-bind="value: comment">
  700. </span>
  701. </span>
  702. <!-- ko if: level() > 0 && $parent.type() == 'struct' && $parent.nested().length > 1 -->
  703. <a data-bind="click: function() { $parent.nested.remove($data); }"><i class="fa fa-minus"></i></a>
  704. <!-- /ko -->
  705. <!-- ko if: $root.createWizard.source.inputFormat() != 'manual' && level() == 0 && (typeof isPartition === 'undefined' || !isPartition()) -->
  706. <!-- ko if: $root.createWizard.source.sample() && $root.createWizard.source.sample().length > 0 -->
  707. <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[0][$index()]"></div>
  708. <!-- ko if: $root.createWizard.source.sample().length > 1 -->
  709. <div class="inline-block muted field-content-preview" data-bind="truncatedText: $root.createWizard.source.sample()[1][$index()]"></div>
  710. <!-- /ko -->
  711. <!-- /ko -->
  712. <!-- ko if: !$root.createWizard.source.sample() || $root.createWizard.source.sample().length === 0 -->
  713. <div class="inline-block muted field-content-preview">${ _("No sample to be shown") }</div>
  714. <!-- /ko -->
  715. <!-- /ko -->
  716. <!-- ko if: type() == 'array' || type() == 'map' || type() == 'struct' -->
  717. <div class="operation" data-bind="template: { name: 'table-field-template', foreach: nested }"></div>
  718. <a data-bind="click: function() { nested.push($root.loadDefaultField({level: level() + 1})); }, visible: type() == 'struct'"><i class="fa fa-plus"></i></a>
  719. <!-- /ko -->
  720. </div>
  721. </script>
  722. <script type="text/html" id="index-field-template">
  723. <label>${ _('Name') }&nbsp;
  724. <input type="text" class="input-large" placeholder="${ _('Field name') }" data-bind="value: name">
  725. </label>
  726. <label class="margin-left-5">${ _('Type') }&nbsp;
  727. <select class="input-small" data-bind="browserAwareSelectize: $root.createWizard.fieldTypes, value: type"></select>
  728. </label>
  729. <a href="javascript:void(0)" title="${ _('Show field properties') }" data-bind="css: {'inactive-action': !showProperties()}, click: function() {showProperties(!showProperties()) }"><i class="fa fa-sliders"></i></a>
  730. <span data-bind="visible: showProperties" class="field-properties">
  731. <label class="checkbox">
  732. <input type="checkbox" data-bind="checked: unique"> ${_('Unique')}
  733. </label>
  734. <label class="checkbox">
  735. <input type="checkbox" data-bind="checked: keep"> ${_('Keep in index')}
  736. </label>
  737. <label class="checkbox">
  738. <input type="checkbox" data-bind="checked: required"> ${_('Required')}
  739. </label>
  740. </span>
  741. <!-- ko if: operations().length == 0 -->
  742. <a class="pointer margin-left-20" data-bind="click: $root.createWizard.addOperation" title="${_('Add Operation')}"><i class="fa fa-plus"></i> ${_('Operation')}</a>
  743. <!-- /ko -->
  744. <div data-bind="foreach: operations">
  745. <div data-bind="template: { name:'operation-template',data:{operation: $data, list: $parent.operations}}"></div>
  746. </div>
  747. <!-- ko if: operations().length > 0 -->
  748. <a class="pointer" data-bind="click: $root.createWizard.addOperation" title="${_('Add Operation')}"><i class="fa fa-plus"></i> ${_('Operation to')} <span data-bind="text: name"></span></a>
  749. <!-- /ko -->
  750. </script>
  751. <script type="text/html" id="operation-template">
  752. <div class="operation">
  753. <select data-bind="browserAwareSelectize: $root.createWizard.operationTypes.map(function(o){return o.name}), value: operation.type"></select>
  754. <!-- ko template: "args-template" --><!-- /ko -->
  755. <!-- ko if: operation.settings().outputType() == "custom_fields" -->
  756. <label class="margin-left-5">${ _('Number of expected fields') }
  757. <input type="number" class="input-mini" data-bind="value: operation.numExpectedFields">
  758. </label>
  759. <!-- /ko -->
  760. <a class="pointer margin-left-20" data-bind="click: function(){$root.createWizard.removeOperation(operation, list)}" title="${ _('Remove') }"><i class="fa fa-times"></i></a>
  761. <div class="margin-left-20" data-bind="foreach: operation.fields">
  762. <div data-bind="template: { name:'index-field-template', data:$data }" class="margin-top-10 field index-field"></div>
  763. </div>
  764. </div>
  765. </script>
  766. <script type="text/html" id="args-template">
  767. <!-- ko foreach: {data: operation.settings().getArguments(), as: 'argument'} -->
  768. <!-- ko template: {name: 'arg-' + argument.type, data: {description: argument.description, value: $parent.operation.settings()[argument.name]}}--><!-- /ko -->
  769. <!-- /ko -->
  770. </script>
  771. <script type="text/html" id="arg-text">
  772. <label>
  773. <div data-bind="text: description"></div>
  774. <input type="text" class="input" data-bind="attr: {placeholder: description}, value: value">
  775. </label>
  776. </script>
  777. <script type="text/html" id="arg-text-delimiter">
  778. <label>
  779. <div data-bind="text: description"></div>
  780. <select data-bind="selectize: $root.createWizard.customDelimiters, selectizeOptions: { onOptionAdd: function(value){ $root.createWizard.customDelimiters.push({ 'value': value, 'name': value }) }, create: true, maxLength: 2 }, value: value, optionsValue: 'value', optionsText: 'name', attr: {placeholder: description}"></select>
  781. </label>
  782. </script>
  783. <script type="text/html" id="arg-checkbox">
  784. <label class="checkbox">
  785. <input type="checkbox" data-bind="checked: value">
  786. <span data-bind="text: description" style="vertical-align: middle"></span>
  787. </label>
  788. </script>
  789. <script type="text/html" id="arg-mapping">
  790. <!-- ko foreach: value-->
  791. <div>
  792. <input type="text" data-bind="value: key, attr: {placeholder: 'key'}">
  793. <input type="text" data-bind="value: value, attr: {placeholder: 'value'}">
  794. <button class="btn" data-bind="click: function(){$parent.value.remove($data)}">${_('Remove Pair')}</button>
  795. </div>
  796. <!-- /ko -->
  797. <button class="btn" data-bind="click: function(){value.push({key: ko.observable(''), value: ko.observable('')})}">${_('Add Pair')}</button>
  798. <br>
  799. </script>
  800. <script type="text/html" id="field-preview-header-template">
  801. <th data-bind="visible: keep, text: name" style="padding-right:60px"></th>
  802. <!-- ko foreach: operations -->
  803. <!--ko foreach: fields -->
  804. <!-- ko template: 'field-preview-header-template' --><!-- /ko -->
  805. <!-- /ko -->
  806. <!--/ko -->
  807. </script>
  808. <script type="text/html" id="output-generated-field-data-template">
  809. <!-- ko foreach: operations -->
  810. <!--ko foreach: fields -->
  811. <td data-bind="visible: keep">[[${_('generated')}]]</td>
  812. <!-- ko template: 'output-generated-field-data-template' --><!-- /ko -->
  813. <!-- /ko -->
  814. <!--/ko -->
  815. </script>
  816. <script type="text/html" id="importerNotebook-progress">
  817. <!-- ko with: selectedNotebook -->
  818. <!-- ko foreach: snippets -->
  819. <div class="progress-snippet progress" data-bind="css: {
  820. 'progress-starting': progress() == 0 && status() == 'running',
  821. 'progress-warning': progress() > 0 && progress() < 100,
  822. 'progress-success': progress() == 100,
  823. 'progress-danger': progress() == 0 && errors().length > 0}" style="background-color: #FFF; width: 100%; height: 4px">
  824. <div class="bar" data-bind="style: {'width': (errors().length > 0 ? 100 : Math.max(2, progress())) + '%'}"></div>
  825. </div>
  826. <div class="snippet-error-container alert alert-error alert-error-gradient" data-bind="visible: errors().length > 0">
  827. <ul class="unstyled" data-bind="foreach: errors">
  828. <li data-bind="text: message"></li>
  829. </ul>
  830. </div>
  831. <!-- /ko -->
  832. <!-- /ko -->
  833. </script>
  834. <script type="text/javascript">
  835. (function () {
  836. ko.options.deferUpdates = true;
  837. var MAPPINGS = {
  838. SOLR_TO_HIVE: {
  839. "string": "string",
  840. "long": "bigint",
  841. "double": "double",
  842. "date": "date"
  843. },
  844. get: function(type, key, defaultValue) {
  845. return type[key] || defaultValue
  846. }
  847. }
  848. var fieldNum = 0;
  849. var getNewFieldName = function () {
  850. fieldNum++;
  851. return "new_field_" + fieldNum
  852. };
  853. var createDefaultField = function () {
  854. var defaultField = ko.mapping.fromJS(${default_field_type | n});
  855. defaultField.name = ko.observable(getNewFieldName());
  856. return defaultField;
  857. };
  858. var Operation = function (type) {
  859. var self = this;
  860. var createArgumentValue = function (arg) {
  861. if (arg.type == "mapping") {
  862. return ko.observableArray([]);
  863. }
  864. else if (arg.type == "checkbox") {
  865. return ko.observable(false);
  866. }
  867. else {
  868. return ko.observable("");
  869. }
  870. }
  871. var constructSettings = function (type) {
  872. var settings = {};
  873. var operation = viewModel.createWizard.operationTypes.find(function (currOperation) {
  874. return currOperation.name == type;
  875. });
  876. for (var i = 0; i < operation.args.length; i++) {
  877. var argVal = createArgumentValue(operation.args[i]);
  878. if (operation.args[i].type == "checkbox" && operation.outputType == "checkbox_fields") {
  879. argVal.subscribe(function (newVal) {
  880. if (newVal) {
  881. self.fields.push(createDefaultField());
  882. }
  883. else {
  884. self.fields.pop();
  885. }
  886. });
  887. }
  888. settings[operation.args[i].name] = argVal;
  889. }
  890. settings.getArguments = function () {
  891. return operation.args
  892. };
  893. settings.outputType = function () {
  894. return operation.outputType;
  895. }
  896. return settings;
  897. };
  898. var init = function () {
  899. self.fields([]);
  900. self.numExpectedFields(0);
  901. self.numExpectedFields.subscribe(function (numExpectedFields) {
  902. if (numExpectedFields < self.fields().length) {
  903. self.fields(self.fields().slice(0, numExpectedFields));
  904. }
  905. else if (numExpectedFields > self.fields().length) {
  906. var difference = numExpectedFields - self.fields().length;
  907. for (var i = 0; i < difference; i++) {
  908. self.fields.push(createDefaultField());
  909. }
  910. }
  911. });
  912. self.settings(constructSettings(self.type()));
  913. }
  914. self.load = function (data) {
  915. self.numExpectedFields(data.numExpectedFields);
  916. var newSettings = constructSettings(data.type);
  917. for (var key in data.settings) {
  918. newSettings[key] = ko.mapping.fromJS(data.settings[key]);
  919. }
  920. self.settings(newSettings);
  921. data.fields.forEach(function (field) {
  922. self.fields.push(loadField(field));
  923. });
  924. }
  925. self.type = ko.observable(type);
  926. self.fields = ko.observableArray();
  927. self.numExpectedFields = ko.observable();
  928. self.settings = ko.observable();
  929. init();
  930. self.type.subscribe(function (newType) {
  931. init();
  932. });
  933. }
  934. var FileType = function (typeName, args) {
  935. var self = this;
  936. var type;
  937. var init = function () {
  938. self.type = ko.observable(typeName);
  939. var types = viewModel.createWizard.fileTypes;
  940. for (var i = 0; i < types.length; i++) {
  941. if (types[i].name == typeName) {
  942. type = types[i];
  943. break;
  944. }
  945. }
  946. for (var i = 0; i < type.args.length; i++) {
  947. self[type.args[i].name] = ko.observable();
  948. }
  949. if (args) {
  950. loadFromObj(args);
  951. }
  952. for (var i = 0; i < type.args.length; i++) {
  953. self[type.args[i].name].subscribe(viewModel.createWizard.guessFieldTypes);
  954. }
  955. }
  956. var loadFromObj = function (args) {
  957. for (var attr in args) {
  958. self[attr] = ko.mapping.fromJS(args[attr]);
  959. }
  960. }
  961. self.getArguments = function () {
  962. return type.args;
  963. }
  964. self.isCustomizable = function () {
  965. return type.isCustomizable;
  966. }
  967. init();
  968. }
  969. var Source = function (vm, wizard) {
  970. var self = this;
  971. self.name = ko.observable('');
  972. self.sample = ko.observableArray();
  973. self.sampleCols = ko.observableArray();
  974. self.inputFormat = ko.observable(wizard.prefill.source_type() == 'manual' ? 'manual' : 'file');
  975. self.inputFormat.subscribe(function(val) {
  976. wizard.destination.columns.removeAll();
  977. self.sample.removeAll();
  978. self.path('');
  979. resizeElements();
  980. });
  981. self.inputFormatsAll = ko.observableArray([
  982. {'value': 'file', 'name': 'File'},
  983. {'value': 'manual', 'name': 'Manually'},
  984. % if ENABLE_NEW_INDEXER.get():
  985. {'value': 'query', 'name': 'SQL Query'},
  986. {'value': 'table', 'name': 'Table'},
  987. % endif
  988. ##{'value': 'dbms', 'name': 'DBMS'},
  989. ##{'value': 'text', 'name': 'Paste Text'},
  990. ]);
  991. self.inputFormatsManual = ko.observableArray([
  992. {'value': 'manual', 'name': 'Manually'}
  993. ]);
  994. self.inputFormats = ko.pureComputed(function() {
  995. if (wizard.prefill.source_type() == 'manual') {
  996. return self.inputFormatsManual();
  997. } else {
  998. return self.inputFormatsAll();
  999. }
  1000. });
  1001. // File
  1002. self.path = ko.observable('');
  1003. self.path.subscribe(function(val) {
  1004. if (val) {
  1005. vm.createWizard.guessFormat();
  1006. vm.createWizard.destination.nonDefaultLocation(val);
  1007. }
  1008. resizeElements();
  1009. });
  1010. self.isObjectStore = ko.computed(function() {
  1011. return self.inputFormat() == 'file' && /^s3a:\/\/.*$/.test(self.path());
  1012. });
  1013. self.isObjectStore.subscribe(function(newVal) {
  1014. vm.createWizard.destination.useDefaultLocation(! newVal);
  1015. });
  1016. // Table
  1017. self.table = ko.observable('');
  1018. self.tableName = ko.computed(function() {
  1019. return self.table().indexOf('.') > 0 ? self.table().split('.', 2)[1] : self.table();
  1020. });
  1021. self.databaseName = ko.computed(function() {
  1022. return self.table().indexOf('.') > 0 ? self.table().split('.', 2)[0] : 'default';
  1023. });
  1024. self.table.subscribe(function(val) {
  1025. resizeElements();
  1026. });
  1027. self.apiHelperType = ko.observable('${ sourceType }');
  1028. // Queries
  1029. self.query = ko.observable('');
  1030. self.draggedQuery = ko.observable();
  1031. self.format = ko.observable();
  1032. self.format.subscribe(function(newVal) {
  1033. if (typeof newVal.hasHeader !== 'undefined') {
  1034. vm.createWizard.destination.hasHeader(newVal.hasHeader());
  1035. newVal.hasHeader.subscribe(function(newVal) {
  1036. vm.createWizard.destination.hasHeader(newVal);
  1037. });
  1038. }
  1039. if (typeof newVal.fieldSeparator !== 'undefined') {
  1040. vm.createWizard.destination.useCustomDelimiters(newVal.fieldSeparator() != ',');
  1041. vm.createWizard.destination.customFieldDelimiter(newVal.fieldSeparator());
  1042. newVal.fieldSeparator.subscribe(function(newVal) {
  1043. vm.createWizard.destination.customFieldDelimiter(newVal);
  1044. });
  1045. }
  1046. });
  1047. self.show = ko.computed(function() {
  1048. if (self.inputFormat() == 'file') {
  1049. return self.path().length > 0;
  1050. } else if (self.inputFormat() == 'table') {
  1051. return self.tableName().length > 0;
  1052. } else if (self.inputFormat() == 'query') {
  1053. return self.query();
  1054. } else if (self.inputFormat() == 'manual') {
  1055. return true;
  1056. }
  1057. });
  1058. self.defaultName = ko.computed(function() {
  1059. var name = ''
  1060. if (self.inputFormat() == 'file') {
  1061. name = wizard.prefill.target_path().length > 0 ? wizard.prefill.target_path() : 'default';
  1062. if (self.path()) {
  1063. name += '.' + self.path().split('/').pop().split('.')[0];
  1064. }
  1065. } else if (self.inputFormat() == 'table') {
  1066. if (self.table().split('.', 2).length == 2) {
  1067. name = self.table();
  1068. }
  1069. } else if (self.inputFormat() == 'query') {
  1070. if (self.query()) {
  1071. name = self.name();
  1072. }
  1073. } else if (self.inputFormat() == 'manual') {
  1074. name = wizard.prefill.target_path().length > 0 ? wizard.prefill.target_path() + '.' : '';
  1075. }
  1076. return name.replace(/ /g, '_').toLowerCase();
  1077. });
  1078. self.defaultName.subscribe(function(newVal) {
  1079. vm.createWizard.destination.name(newVal);
  1080. });
  1081. };
  1082. var Destination = function (vm, wizard) {
  1083. var self = this;
  1084. self.name = ko.observable('').extend({throttle: 500});
  1085. self.name.subscribe(function(name) {
  1086. var exists = false;
  1087. if (name.length == 0) {
  1088. self.isTargetExisting(false);
  1089. self.isTargetChecking(false);
  1090. }
  1091. else if (self.outputFormat() == 'file') {
  1092. // Todo
  1093. // self.path()
  1094. }
  1095. else if (self.outputFormat() == 'table') {
  1096. if (self.tableName() !== '') {
  1097. self.isTargetExisting(false);
  1098. self.isTargetChecking(true);
  1099. $.get("/" + (self.apiHelperType() == 'hive' ? 'beeswax' : self.apiHelperType()) + "/api/autocomplete/" + self.databaseName() + '/' + self.tableName(), function (data) {
  1100. self.isTargetExisting(data.code != 500 && data.code != 404);
  1101. self.isTargetChecking(false);
  1102. }).fail(function (xhr, textStatus, errorThrown) { self.isTargetExisting(false); self.isTargetChecking(false); });
  1103. }
  1104. else {
  1105. self.isTargetExisting(false);
  1106. self.isTargetChecking(false);
  1107. }
  1108. }
  1109. else if (self.outputFormat() == 'database') {
  1110. if (self.databaseName() !== '') {
  1111. self.isTargetExisting(false);
  1112. self.isTargetChecking(true);
  1113. $.get("/" + (self.apiHelperType() == 'hive' ? 'beeswax' : self.apiHelperType()) + "/api/autocomplete/" + self.databaseName(), function (data) {
  1114. self.isTargetExisting(data.tables_meta && data.tables_meta.length > 0);
  1115. self.isTargetChecking(false);
  1116. }).fail(function (xhr, textStatus, errorThrown) { self.isTargetExisting(false); self.isTargetChecking(false); });
  1117. }
  1118. else {
  1119. self.isTargetExisting(false);
  1120. self.isTargetChecking(false);
  1121. }
  1122. }
  1123. else if (self.outputFormat() == 'index') {
  1124. $.post("/search/get_collection", {
  1125. name: self.name()
  1126. }, function (data) {
  1127. self.isTargetExisting(data.status == 0);
  1128. self.isTargetChecking(false);
  1129. }).fail(function (xhr, textStatus, errorThrown) { self.isTargetExisting(false); self.isTargetChecking(false); });
  1130. }
  1131. resizeElements();
  1132. });
  1133. self.apiHelperType = ko.observable('${ sourceType }');
  1134. self.description = ko.observable('');
  1135. self.outputFormat = ko.observable(wizard.prefill.target_type() || 'table');
  1136. self.outputFormat.subscribe(function (newValue) {
  1137. if (newValue && newValue != 'database' && (newValue == 'table' && wizard.source.path().length > 0)) {
  1138. wizard.guessFieldTypes();
  1139. resizeElements();
  1140. }
  1141. });
  1142. self.outputFormatsList = ko.observableArray([
  1143. {'name': 'Table', 'value': 'table'},
  1144. {'name': 'Solr index', 'value': 'index'},
  1145. {'name': 'File', 'value': 'file'},
  1146. {'name': 'Database', 'value': 'database'},
  1147. ]);
  1148. self.outputFormats = ko.computed(function() {
  1149. return $.grep(self.outputFormatsList(), function(format) {
  1150. if (format.value == 'database' && wizard.source.inputFormat() != 'manual') {
  1151. return false;
  1152. }
  1153. else if (format.value == 'file' && wizard.source.inputFormat() != 'manual') {
  1154. return false;
  1155. }
  1156. return true;
  1157. })
  1158. });
  1159. wizard.prefill.target_type.subscribe(function(newValue) {
  1160. self.outputFormat(newValue || 'table');
  1161. if (newValue == 'database') {
  1162. vm.currentStep(2);
  1163. } else {
  1164. vm.currentStep(1);
  1165. }
  1166. });
  1167. self.format = ko.observable();
  1168. self.columns = ko.observableArray();
  1169. // UI
  1170. self.bulkColumnNames = ko.observable('');
  1171. self.showProperties = ko.observable(false);
  1172. self.columns.subscribe(function (newVal) {
  1173. self.bulkColumnNames(newVal.map(function (item) {
  1174. return item.name()
  1175. }).join(','));
  1176. });
  1177. self.processBulkColumnNames = function () {
  1178. var val = self.bulkColumnNames();
  1179. try {
  1180. if (val.indexOf("\"") == -1 && val.indexOf("'") == -1) {
  1181. val = '"' + val.replace(/,/gi, '","') + '"';
  1182. }
  1183. if (val.indexOf("[") == -1) {
  1184. val = "[" + val + "]";
  1185. }
  1186. var parsed = JSON.parse(val);
  1187. self.columns().forEach(function (item, cnt) {
  1188. if ($.trim(parsed[cnt]) !== '') {
  1189. item.name($.trim(parsed[cnt]));
  1190. }
  1191. });
  1192. }
  1193. catch (err) {
  1194. }
  1195. $('#fieldsBulkEditor').modal('hide');
  1196. }
  1197. self.isTargetExisting = ko.observable();
  1198. self.isTargetChecking = ko.observable(false);
  1199. self.existingTargetUrl = ko.computed(function() { // Should open generic sample popup instead
  1200. if (self.isTargetExisting()) {
  1201. if (self.outputFormat() == 'file') {
  1202. // Todo
  1203. return '';
  1204. }
  1205. else if (self.outputFormat() == 'table') {
  1206. return '/metastore/table/' + self.databaseName() + '/' + self.tableName();
  1207. }
  1208. else if (self.outputFormat() == 'database') {
  1209. return '/metastore/tables/' + self.databaseName();
  1210. }
  1211. else if (self.outputFormat() == 'index') {
  1212. return '${ url("indexer:collections") }#edit/' + self.name();
  1213. }
  1214. }
  1215. return '';
  1216. });
  1217. // Table
  1218. self.tableName = ko.computed(function() {
  1219. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[1] : self.name();
  1220. });
  1221. self.databaseName = ko.computed(function() {
  1222. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[0] : (self.name() !== '' ? self.name() : 'default');
  1223. });
  1224. self.tableFormat = ko.observable('text');
  1225. self.tableFormat.subscribe(function(newVal) {
  1226. if (newVal == 'kudu' && self.kuduPartitionColumns().length == 0) {
  1227. self.kuduPartitionColumns.push(ko.mapping.fromJS(self.KUDU_DEFAULT_PARTITION_COLUMN));
  1228. }
  1229. });
  1230. self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN = {values: [{value: ''}], name: 'VALUES', lower_val: 0, include_lower_val: '<=', upper_val: 1, include_upper_val: '<='};
  1231. self.KUDU_DEFAULT_PARTITION_COLUMN = {columns: [], range_partitions: [self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN], name: 'HASH', int_val: 16};
  1232. self.tableFormats = ko.observableArray([
  1233. {'value': 'text', 'name': 'Text'},
  1234. {'value': 'parquet', 'name': 'Parquet'},
  1235. {'value': 'kudu', 'name': 'Kudu'},
  1236. {'value': 'csv', 'name': 'Csv'},
  1237. {'value': 'avro', 'name': 'Avro'},
  1238. {'value': 'json', 'name': 'Json'},
  1239. {'value': 'regexp', 'name': 'Regexp'},
  1240. {'value': 'orc', 'name': 'ORC'},
  1241. ]);
  1242. self.partitionColumns = ko.observableArray();
  1243. self.kuduPartitionColumns = ko.observableArray();
  1244. self.primaryKeys = ko.observableArray();
  1245. self.primaryKeyObjects = ko.observableArray();
  1246. self.importData = ko.observable(true);
  1247. self.useDefaultLocation = ko.observable(true);
  1248. self.nonDefaultLocation = ko.observable('');
  1249. self.hasHeader = ko.observable(true);
  1250. self.useCustomDelimiters = ko.observable(false);
  1251. self.customFieldDelimiter = ko.observable(',');
  1252. self.customCollectionDelimiter = ko.observable('\\002');
  1253. self.customMapDelimiter = ko.observable('\\003');
  1254. self.customRegexp = ko.observable('');
  1255. // Index
  1256. };
  1257. var CreateWizard = function (vm) {
  1258. var self = this;
  1259. var guessFieldTypesXhr;
  1260. self.fileType = ko.observable();
  1261. self.fileType.subscribe(function (newType) {
  1262. if (self.source.format()) {
  1263. self.source.format().type(newType.name);
  1264. }
  1265. });
  1266. self.fileTypeName = ko.observable();
  1267. self.fileTypeName.subscribe(function (newType) {
  1268. for (var i = 0; i < self.fileTypes.length; i++) {
  1269. if (self.fileTypes[i].name == newType) {
  1270. self.fileType(self.fileTypes[i]);
  1271. break;
  1272. }
  1273. }
  1274. });
  1275. self.operationTypes = ${operators_json | n};
  1276. self.fieldTypes = ${fields_json | n}.solr;
  1277. self.hivePrimitiveFieldTypes = ${fields_json | n}.hivePrimitive;
  1278. self.hiveFieldTypes = ${fields_json | n}.hive;
  1279. self.fileTypes = ${file_types_json | n};
  1280. self.prefill = ko.mapping.fromJS(${prefill | n});
  1281. self.prefill.source_type.subscribe(function(newValue) {
  1282. self.source.inputFormat(newValue == 'manual' ? 'manual' : 'file');
  1283. });
  1284. self.show = ko.observable(true);
  1285. self.showCreate = ko.observable(false);
  1286. self.source = new Source(vm, self);
  1287. self.destination = new Destination(vm, self);
  1288. self.customDelimiters = ko.observableArray([
  1289. {'value': ',', 'name': 'Comma (,)'},
  1290. {'value': '\\t', 'name': '^Tab (\\t)'},
  1291. {'value': '\\n', 'name': 'New line'},
  1292. {'value': ' ', 'name': 'Space'},
  1293. {'value': '"', 'name': 'Double Quote'},
  1294. {'value': '\\001', 'name': '^A (\\001)'},
  1295. {'value': '\\002', 'name': '^B (\\002)'},
  1296. {'value': '\\003', 'name': '^C (\\003)'},
  1297. ]);
  1298. self.editorId = ko.observable();
  1299. self.jobId = ko.observable();
  1300. self.editorVM = null;
  1301. self.indexingStarted = ko.observable(false);
  1302. self.isValidDestination = ko.pureComputed(function() {
  1303. return self.destination.name().length > 0 && (['table', 'database'].indexOf(self.destination.outputFormat()) == -1 || /^([a-zA-Z0-9_]+\.)?[a-zA-Z0-9_]+$/.test(self.destination.name()));
  1304. });
  1305. self.readyToIndex = ko.computed(function () {
  1306. var validFields = self.destination.columns().length || self.destination.outputFormat() == 'database';
  1307. var validTableColumns = self.destination.outputFormat() != 'table' || ($.grep(self.destination.columns(), function(column) {
  1308. return column.name().length == 0;
  1309. }).length == 0
  1310. && $.grep(self.destination.partitionColumns(), function(column) {
  1311. return column.name().length == 0 || (self.source.inputFormat() != 'manual' && column.partitionValue().length == 0);
  1312. }).length == 0
  1313. );
  1314. var isTargetAlreadyExisting = ! self.destination.isTargetExisting() || self.destination.outputFormat() == 'index';
  1315. var isValidTable = self.destination.outputFormat() != 'table' || (
  1316. self.destination.tableFormat() != 'kudu' || (self.destination.kuduPartitionColumns().length > 0 &&
  1317. $.grep(self.destination.kuduPartitionColumns(), function(partition) { return partition.columns().length > 0 }).length == self.destination.kuduPartitionColumns().length && self.destination.primaryKeys().length > 0)
  1318. );
  1319. return self.isValidDestination() && validFields && validTableColumns && isTargetAlreadyExisting && isValidTable;
  1320. });
  1321. self.formatTypeSubscribed = false;
  1322. self.source.format.subscribe(function (newVal) {
  1323. for (var i = 0; i < self.fileTypes.length; i++) {
  1324. if (self.fileTypes[i].name == self.source.format().type()) {
  1325. self.fileType(self.fileTypes[i]);
  1326. self.fileTypeName(self.fileTypes[i].name);
  1327. break;
  1328. }
  1329. }
  1330. if (self.source.format().type) {
  1331. if (!self.formatTypeSubscribed) {
  1332. self.formatTypeSubscribed = true;
  1333. self.source.format().type.subscribe(function (newType) {
  1334. self.source.format(new FileType(newType));
  1335. self.destination.columns.removeAll();
  1336. self.guessFieldTypes();
  1337. });
  1338. }
  1339. }
  1340. });
  1341. self.isGuessingFormat = ko.observable(false);
  1342. self.guessFormat = function () {
  1343. self.isGuessingFormat(true);
  1344. self.destination.columns.removeAll();
  1345. $.post("${ url('indexer:guess_format') }", {
  1346. "fileFormat": ko.mapping.toJSON(self.source)
  1347. }, function (resp) {
  1348. if (resp.status != 0) {
  1349. $(document).trigger("error", resp.message);
  1350. } else {
  1351. var newFormat = ko.mapping.fromJS(new FileType(resp['type'], resp));
  1352. self.source.format(newFormat);
  1353. self.guessFieldTypes();
  1354. }
  1355. self.isGuessingFormat(false);
  1356. viewModel.wizardEnabled(true);
  1357. }).fail(function (xhr, textStatus, errorThrown) {
  1358. $(document).trigger("error", xhr.responseText);
  1359. viewModel.isLoading(false);
  1360. self.isGuessingFormat(false);
  1361. });
  1362. };
  1363. self.isGuessingFieldTypes = ko.observable(false);
  1364. self.guessFieldTypes = function () {
  1365. if (guessFieldTypesXhr) {
  1366. guessFieldTypesXhr.abort();
  1367. }
  1368. self.isGuessingFieldTypes(true);
  1369. guessFieldTypesXhr = $.post("${ url('indexer:guess_field_types') }", {
  1370. "fileFormat": ko.mapping.toJSON(self.source)
  1371. }, function (resp) {
  1372. resp.columns.forEach(function (entry, i, arr) {
  1373. if (self.destination.outputFormat() === 'table'){
  1374. entry.type = MAPPINGS.get(MAPPINGS.SOLR_TO_HIVE, entry.type, 'string');
  1375. }
  1376. arr[i] = loadField(entry, self.destination, i);
  1377. });
  1378. self.source.sampleCols(resp.sample_cols ? resp.sample_cols : resp.columns);
  1379. self.source.sample(resp.sample);
  1380. self.destination.columns(resp.columns);
  1381. self.isGuessingFieldTypes(false);
  1382. }).fail(function (xhr, textStatus, errorThrown) {
  1383. $(document).trigger("error", xhr.responseText);
  1384. self.isGuessingFieldTypes(false);
  1385. viewModel.isLoading(false);
  1386. });
  1387. };
  1388. self.isIndexing = ko.observable(false);
  1389. self.indexingError = ko.observable(false);
  1390. self.indexingSuccess = ko.observable(false);
  1391. self.indexFile = function () {
  1392. if (! self.readyToIndex()) {
  1393. return;
  1394. }
  1395. %if not is_embeddable:
  1396. self.indexingStarted(true);
  1397. viewModel.isLoading(true);
  1398. self.isIndexing(true);
  1399. $.post("${ url('indexer:importer_submit') }", {
  1400. "source": ko.mapping.toJSON(self.source),
  1401. "destination": ko.mapping.toJSON(self.destination)
  1402. }, function (resp) {
  1403. if (resp.status != 0) {
  1404. $(document).trigger("error", resp.message);
  1405. self.indexingStarted(false);
  1406. self.isIndexing(false);
  1407. } else {
  1408. self.showCreate(true);
  1409. self.editorId(resp.history_id);
  1410. self.jobId(resp.handle.id);
  1411. $('#importerNotebook').html($('#importerNotebook-progress').html());
  1412. self.editorVM = new EditorViewModel(resp.history_uuid, '', {
  1413. user: '${ user.username }',
  1414. userId: ${ user.id },
  1415. languages: [{name: "Java", type: "java"}, {name: "Hive SQL", type: "hive"}], // TODO reuse
  1416. snippetViewSettings: {
  1417. java : {
  1418. snippetIcon: 'fa-file-archive-o '
  1419. },
  1420. hive: {
  1421. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1422. aceMode: 'ace/mode/hive',
  1423. snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
  1424. sqlDialect: true
  1425. },
  1426. impala: {
  1427. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1428. aceMode: 'ace/mode/impala',
  1429. snippetImage: '${ static("impala/art/icon_impala_48.png") }',
  1430. sqlDialect: true
  1431. }
  1432. }
  1433. });
  1434. self.editorVM.editorMode(true);
  1435. self.editorVM.isNotificationManager(true);
  1436. ko.cleanNode($("#importerNotebook")[0]);
  1437. ko.applyBindings(self.editorVM, $("#importerNotebook")[0]);
  1438. self.editorVM.openNotebook(resp.history_uuid, null, true, function(){
  1439. self.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
  1440. if (val == 100){
  1441. self.indexingStarted(false);
  1442. self.isIndexing(false);
  1443. self.indexingSuccess(true);
  1444. }
  1445. });
  1446. self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
  1447. if (val == 'failed'){
  1448. self.isIndexing(false);
  1449. self.indexingStarted(false);
  1450. self.indexingError(true);
  1451. } else if (val == 'available') {
  1452. var snippet = self.editorVM.selectedNotebook().snippets()[0]; // Could be native to editor at some point
  1453. if (! snippet.result.handle().has_more_statements) {
  1454. if (self.editorVM.selectedNotebook().onSuccessUrl()) {
  1455. huePubSub.publish('assist.clear.db.cache', {sourceType: self.source.apiHelperType()});
  1456. window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
  1457. }
  1458. } else { // Perform last DROP statement execute
  1459. snippet.execute();
  1460. }
  1461. }
  1462. });
  1463. self.editorVM.selectedNotebook().snippets()[0].checkStatus();
  1464. });
  1465. }
  1466. viewModel.isLoading(false);
  1467. }).fail(function (xhr, textStatus, errorThrown) {
  1468. $(document).trigger("error", xhr.responseText);
  1469. viewModel.isLoading(false);
  1470. self.indexingStarted(false);
  1471. self.isIndexing(false);
  1472. });
  1473. % else:
  1474. $.post("${ url('indexer:importer_submit') }", {
  1475. "source": ko.mapping.toJSON(self.source),
  1476. "destination": ko.mapping.toJSON(self.destination)
  1477. }, function (resp) {
  1478. if (resp.history_uuid) {
  1479. $.jHueNotify.info("${ _('Task ') }" + resp.history_uuid + "${_(' submitted.') }");
  1480. huePubSub.publish('notebook.task.submitted', resp.history_uuid);
  1481. } else {
  1482. $(document).trigger("error", data.message);
  1483. }
  1484. }).fail(function (xhr, textStatus, errorThrown) {
  1485. $(document).trigger("error", xhr.responseText);
  1486. });
  1487. % endif
  1488. hueAnalytics.log('importer', 'submit/' + self.source.inputFormat() + '/' + self.destination.outputFormat());
  1489. }
  1490. self.removeOperation = function (operation, operationList) {
  1491. operationList.remove(operation);
  1492. hueAnalytics.log('importer', 'step/removeOperation');
  1493. }
  1494. self.addOperation = function (field) {
  1495. field.operations.push(new Operation("split"));
  1496. hueAnalytics.log('importer', 'step/addOperation');
  1497. }
  1498. self.load = function (state) {
  1499. self.source.name(state.name);
  1500. self.source.show(state.show);
  1501. self.source.path(state.path);
  1502. self.destination.columns.removeAll();
  1503. if (state.format && 'type' in state.format) {
  1504. var koFormat = ko.mapping.fromJS(new FileType(state.format.type, state.format));
  1505. self.source.format(koFormat);
  1506. }
  1507. if (state.columns){
  1508. state.columns.forEach(function (currCol) {
  1509. self.destination.columns.push(loadField(currCol));
  1510. });
  1511. }
  1512. }
  1513. };
  1514. var loadDefaultField = function (options) {
  1515. if (! options.name) {
  1516. options.name = getNewFieldName();
  1517. }
  1518. return loadField($.extend({}, ${default_field_type | n}, options));
  1519. }
  1520. var loadField = function (currField, parent, idx) {
  1521. var koField = ko.mapping.fromJS(currField);
  1522. if (koField.name && parent) {
  1523. koField.name.subscribe(function (newVal) {
  1524. if (newVal.indexOf(',') > -1) {
  1525. var fields = newVal.split(',');
  1526. fields.forEach(function (val, i) {
  1527. if (i + idx < parent.columns().length) {
  1528. parent.columns()[i + idx].name(val);
  1529. }
  1530. });
  1531. }
  1532. parent.bulkColumnNames(parent.columns().map(function (item) {
  1533. return item.name()
  1534. }).join(','));
  1535. });
  1536. }
  1537. koField.operations.removeAll();
  1538. currField.operations.forEach(function (operationData) {
  1539. var operation = new Operation(operationData.type);
  1540. operation.load(operationData);
  1541. koField.operations.push(operation);
  1542. });
  1543. var autoExpand = function (newVal) {
  1544. if ((newVal == 'array' || newVal == 'map' || newVal == 'struct') && koField.nested().length == 0) {
  1545. koField.nested.push(loadDefaultField({level: koField.level() + 1}));
  1546. }
  1547. };
  1548. koField.type.subscribe(autoExpand);
  1549. koField.keyType.subscribe(autoExpand);
  1550. return koField;
  1551. }
  1552. var IndexerViewModel = function () {
  1553. var self = this;
  1554. self.apiHelper = ApiHelper.getInstance();
  1555. self.assistAvailable = ko.observable(true);
  1556. self.isLeftPanelVisible = ko.observable();
  1557. self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
  1558. self.loadDefaultField = loadDefaultField;
  1559. self.createWizard = new CreateWizard(self);
  1560. // Wizard related
  1561. self.wizardEnabled = ko.observable(false);
  1562. self.currentStep = ko.observable(self.createWizard.prefill.target_type() == 'database' ? 2 : 1);
  1563. self.currentStep.subscribe(function () {
  1564. $('.content-panel').scrollTop(0);
  1565. });
  1566. self.previousStepVisible = ko.pureComputed(function(){
  1567. return self.currentStep() > 1 && self.createWizard.destination.outputFormat() != 'database';
  1568. });
  1569. self.nextStepVisible = ko.pureComputed(function(){
  1570. return self.currentStep() < 3 && self.wizardEnabled();
  1571. });
  1572. self.nextStep = function () {
  1573. if (self.nextStepVisible()){
  1574. self.currentStep(self.currentStep() + 1);
  1575. hueAnalytics.log('importer', 'step/' + self.currentStep());
  1576. }
  1577. }
  1578. self.previousStep = function () {
  1579. if (self.previousStepVisible()){
  1580. self.currentStep(self.currentStep() - 1);
  1581. hueAnalytics.log('importer', 'step/' + self.currentStep());
  1582. }
  1583. }
  1584. self.isLoading = ko.observable(false);
  1585. };
  1586. var viewModel;
  1587. function resizeElements () {
  1588. var $contentPanel = $('#importerComponents').find('.content-panel-inner');
  1589. $('.form-actions').width($contentPanel.width() - 50);
  1590. $('.step-indicator-fixed').width($contentPanel.width());
  1591. document.styleSheets[0].addRule('.step-indicator li:first-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()) + 'px');
  1592. document.styleSheets[0].addRule('.step-indicator li:first-child:before','left: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()/2) + 'px');
  1593. document.styleSheets[0].addRule('.step-indicator li:last-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()) + 'px');
  1594. document.styleSheets[0].addRule('.step-indicator li:last-child:before','right: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()/2) + 'px');
  1595. }
  1596. $(document).ready(function () {
  1597. viewModel = new IndexerViewModel();
  1598. ko.applyBindings(viewModel, $('#importerComponents')[0]);
  1599. var draggableMeta = {};
  1600. huePubSub.subscribe('draggable.text.meta', function (meta) {
  1601. draggableMeta = meta;
  1602. });
  1603. huePubSub.subscribe('split.panel.resized', resizeElements);
  1604. hueUtils.waitForRendered('.step-indicator li:first-child .caption', function(el){ return el.width() < $('#importerComponents').find('.content-panel-inner').width()/2 }, resizeElements);
  1605. $(window).on('resize', resizeElements);
  1606. $('.content-panel').droppable({
  1607. accept: ".draggableText",
  1608. drop: function (e, ui) {
  1609. var text = ui.helper.text();
  1610. var generatedName = 'idx';
  1611. switch (draggableMeta.type){
  1612. case 'sql':
  1613. if (draggableMeta.table !== ''){
  1614. generatedName += draggableMeta.table;
  1615. viewModel.createWizard.source.inputFormat('table');
  1616. viewModel.createWizard.source.table(draggableMeta.table);
  1617. }
  1618. break;
  1619. case 'hdfs':
  1620. generatedName += draggableMeta.definition.name;
  1621. viewModel.createWizard.source.inputFormat('file');
  1622. viewModel.createWizard.source.path(draggableMeta.definition.path);
  1623. break;
  1624. case 'document':
  1625. if (draggableMeta.definition.type === 'query-hive'){
  1626. generatedName += draggableMeta.definition.name;
  1627. viewModel.createWizard.source.inputFormat('query');
  1628. viewModel.createWizard.source.draggedQuery(draggableMeta.definition.uuid);
  1629. }
  1630. break;
  1631. }
  1632. if (generatedName !== 'idx' && viewModel.createWizard.source.name() === ''){
  1633. viewModel.createWizard.source.name(generatedName);
  1634. }
  1635. }
  1636. });
  1637. });
  1638. })();
  1639. </script>
  1640. </span>
  1641. %if not is_embeddable:
  1642. ${ commonfooter(request, messages) | n,unicode }
  1643. %endif