importer.mako 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  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. % if ENABLE_NEW_INDEXER.get():
  1145. {'name': 'Solr index', 'value': 'index'},
  1146. % endif
  1147. {'name': 'File', 'value': 'file'},
  1148. {'name': 'Database', 'value': 'database'},
  1149. ]);
  1150. self.outputFormats = ko.computed(function() {
  1151. return $.grep(self.outputFormatsList(), function(format) {
  1152. if (format.value == 'database' && wizard.source.inputFormat() != 'manual') {
  1153. return false;
  1154. }
  1155. else if (format.value == 'file' && wizard.source.inputFormat() != 'manual') {
  1156. return false;
  1157. }
  1158. return true;
  1159. })
  1160. });
  1161. wizard.prefill.target_type.subscribe(function(newValue) {
  1162. self.outputFormat(newValue || 'table');
  1163. if (newValue == 'database') {
  1164. vm.currentStep(2);
  1165. } else {
  1166. vm.currentStep(1);
  1167. }
  1168. });
  1169. self.format = ko.observable();
  1170. self.columns = ko.observableArray();
  1171. // UI
  1172. self.bulkColumnNames = ko.observable('');
  1173. self.showProperties = ko.observable(false);
  1174. self.columns.subscribe(function (newVal) {
  1175. self.bulkColumnNames(newVal.map(function (item) {
  1176. return item.name()
  1177. }).join(','));
  1178. });
  1179. self.processBulkColumnNames = function () {
  1180. var val = self.bulkColumnNames();
  1181. try {
  1182. if (val.indexOf("\"") == -1 && val.indexOf("'") == -1) {
  1183. val = '"' + val.replace(/,/gi, '","') + '"';
  1184. }
  1185. if (val.indexOf("[") == -1) {
  1186. val = "[" + val + "]";
  1187. }
  1188. var parsed = JSON.parse(val);
  1189. self.columns().forEach(function (item, cnt) {
  1190. if ($.trim(parsed[cnt]) !== '') {
  1191. item.name($.trim(parsed[cnt]));
  1192. }
  1193. });
  1194. }
  1195. catch (err) {
  1196. }
  1197. $('#fieldsBulkEditor').modal('hide');
  1198. };
  1199. self.isTargetExisting = ko.observable();
  1200. self.isTargetChecking = ko.observable(false);
  1201. self.existingTargetUrl = ko.computed(function() { // Should open generic sample popup instead
  1202. if (self.isTargetExisting()) {
  1203. if (self.outputFormat() == 'file') {
  1204. // Todo
  1205. return '';
  1206. }
  1207. else if (self.outputFormat() == 'table') {
  1208. return '/metastore/table/' + self.databaseName() + '/' + self.tableName();
  1209. }
  1210. else if (self.outputFormat() == 'database') {
  1211. return '/metastore/tables/' + self.databaseName();
  1212. }
  1213. else if (self.outputFormat() == 'index') {
  1214. return '${ url("indexer:collections") }#edit/' + self.name();
  1215. }
  1216. }
  1217. return '';
  1218. });
  1219. // Table
  1220. self.tableName = ko.computed(function() {
  1221. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[1] : self.name();
  1222. });
  1223. self.databaseName = ko.computed(function() {
  1224. return self.outputFormat() == 'table' && self.name().indexOf('.') > 0 ? self.name().split('.', 2)[0] : (self.name() !== '' ? self.name() : 'default');
  1225. });
  1226. self.tableFormat = ko.observable('text');
  1227. self.tableFormat.subscribe(function(newVal) {
  1228. if (newVal == 'kudu' && self.kuduPartitionColumns().length == 0) {
  1229. self.kuduPartitionColumns.push(ko.mapping.fromJS(self.KUDU_DEFAULT_PARTITION_COLUMN));
  1230. }
  1231. });
  1232. self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN = {values: [{value: ''}], name: 'VALUES', lower_val: 0, include_lower_val: '<=', upper_val: 1, include_upper_val: '<='};
  1233. self.KUDU_DEFAULT_PARTITION_COLUMN = {columns: [], range_partitions: [self.KUDU_DEFAULT_RANGE_PARTITION_COLUMN], name: 'HASH', int_val: 16};
  1234. self.tableFormats = ko.observableArray([
  1235. {'value': 'text', 'name': 'Text'},
  1236. {'value': 'parquet', 'name': 'Parquet'},
  1237. {'value': 'kudu', 'name': 'Kudu'},
  1238. {'value': 'csv', 'name': 'Csv'},
  1239. {'value': 'avro', 'name': 'Avro'},
  1240. {'value': 'json', 'name': 'Json'},
  1241. {'value': 'regexp', 'name': 'Regexp'},
  1242. {'value': 'orc', 'name': 'ORC'},
  1243. ]);
  1244. self.partitionColumns = ko.observableArray();
  1245. self.kuduPartitionColumns = ko.observableArray();
  1246. self.primaryKeys = ko.observableArray();
  1247. self.primaryKeyObjects = ko.observableArray();
  1248. self.importData = ko.observable(true);
  1249. self.useDefaultLocation = ko.observable(true);
  1250. self.nonDefaultLocation = ko.observable('');
  1251. self.hasHeader = ko.observable(true);
  1252. self.useCustomDelimiters = ko.observable(false);
  1253. self.customFieldDelimiter = ko.observable(',');
  1254. self.customCollectionDelimiter = ko.observable('\\002');
  1255. self.customMapDelimiter = ko.observable('\\003');
  1256. self.customRegexp = ko.observable('');
  1257. // Index
  1258. };
  1259. var CreateWizard = function (vm) {
  1260. var self = this;
  1261. var guessFieldTypesXhr;
  1262. self.fileType = ko.observable();
  1263. self.fileType.subscribe(function (newType) {
  1264. if (self.source.format()) {
  1265. self.source.format().type(newType.name);
  1266. }
  1267. });
  1268. self.fileTypeName = ko.observable();
  1269. self.fileTypeName.subscribe(function (newType) {
  1270. for (var i = 0; i < self.fileTypes.length; i++) {
  1271. if (self.fileTypes[i].name == newType) {
  1272. self.fileType(self.fileTypes[i]);
  1273. break;
  1274. }
  1275. }
  1276. });
  1277. self.operationTypes = ${operators_json | n};
  1278. self.fieldTypes = ${fields_json | n}.solr;
  1279. self.hivePrimitiveFieldTypes = ${fields_json | n}.hivePrimitive;
  1280. self.hiveFieldTypes = ${fields_json | n}.hive;
  1281. self.fileTypes = ${file_types_json | n};
  1282. self.prefill = ko.mapping.fromJS(${prefill | n});
  1283. self.prefill.source_type.subscribe(function(newValue) {
  1284. self.source.inputFormat(newValue == 'manual' ? 'manual' : 'file');
  1285. });
  1286. self.show = ko.observable(true);
  1287. self.showCreate = ko.observable(false);
  1288. self.source = new Source(vm, self);
  1289. self.destination = new Destination(vm, self);
  1290. self.customDelimiters = ko.observableArray([
  1291. {'value': ',', 'name': 'Comma (,)'},
  1292. {'value': '\\t', 'name': '^Tab (\\t)'},
  1293. {'value': '\\n', 'name': 'New line'},
  1294. {'value': ' ', 'name': 'Space'},
  1295. {'value': '"', 'name': 'Double Quote'},
  1296. {'value': '\\001', 'name': '^A (\\001)'},
  1297. {'value': '\\002', 'name': '^B (\\002)'},
  1298. {'value': '\\003', 'name': '^C (\\003)'},
  1299. ]);
  1300. self.editorId = ko.observable();
  1301. self.jobId = ko.observable();
  1302. self.editorVM = null;
  1303. self.indexingStarted = ko.observable(false);
  1304. self.isValidDestination = ko.pureComputed(function() {
  1305. 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()));
  1306. });
  1307. self.readyToIndex = ko.computed(function () {
  1308. var validFields = self.destination.columns().length || self.destination.outputFormat() == 'database';
  1309. var validTableColumns = self.destination.outputFormat() != 'table' || ($.grep(self.destination.columns(), function(column) {
  1310. return column.name().length == 0;
  1311. }).length == 0
  1312. && $.grep(self.destination.partitionColumns(), function(column) {
  1313. return column.name().length == 0 || (self.source.inputFormat() != 'manual' && column.partitionValue().length == 0);
  1314. }).length == 0
  1315. );
  1316. var isTargetAlreadyExisting = ! self.destination.isTargetExisting() || self.destination.outputFormat() == 'index';
  1317. var isValidTable = self.destination.outputFormat() != 'table' || (
  1318. self.destination.tableFormat() != 'kudu' || (self.destination.kuduPartitionColumns().length > 0 &&
  1319. $.grep(self.destination.kuduPartitionColumns(), function(partition) { return partition.columns().length > 0 }).length == self.destination.kuduPartitionColumns().length && self.destination.primaryKeys().length > 0)
  1320. );
  1321. return self.isValidDestination() && validFields && validTableColumns && isTargetAlreadyExisting && isValidTable;
  1322. });
  1323. self.formatTypeSubscribed = false;
  1324. self.source.format.subscribe(function (newVal) {
  1325. for (var i = 0; i < self.fileTypes.length; i++) {
  1326. if (self.fileTypes[i].name == self.source.format().type()) {
  1327. self.fileType(self.fileTypes[i]);
  1328. self.fileTypeName(self.fileTypes[i].name);
  1329. break;
  1330. }
  1331. }
  1332. if (self.source.format().type) {
  1333. if (!self.formatTypeSubscribed) {
  1334. self.formatTypeSubscribed = true;
  1335. self.source.format().type.subscribe(function (newType) {
  1336. self.source.format(new FileType(newType));
  1337. self.destination.columns.removeAll();
  1338. self.guessFieldTypes();
  1339. });
  1340. }
  1341. }
  1342. });
  1343. self.isGuessingFormat = ko.observable(false);
  1344. self.guessFormat = function () {
  1345. self.isGuessingFormat(true);
  1346. self.destination.columns.removeAll();
  1347. $.post("${ url('indexer:guess_format') }", {
  1348. "fileFormat": ko.mapping.toJSON(self.source)
  1349. }, function (resp) {
  1350. if (resp.status != 0) {
  1351. $(document).trigger("error", resp.message);
  1352. } else {
  1353. var newFormat = ko.mapping.fromJS(new FileType(resp['type'], resp));
  1354. self.source.format(newFormat);
  1355. self.guessFieldTypes();
  1356. }
  1357. self.isGuessingFormat(false);
  1358. viewModel.wizardEnabled(true);
  1359. }).fail(function (xhr, textStatus, errorThrown) {
  1360. $(document).trigger("error", xhr.responseText);
  1361. viewModel.isLoading(false);
  1362. self.isGuessingFormat(false);
  1363. });
  1364. };
  1365. self.isGuessingFieldTypes = ko.observable(false);
  1366. self.guessFieldTypes = function () {
  1367. if (guessFieldTypesXhr) {
  1368. guessFieldTypesXhr.abort();
  1369. }
  1370. self.isGuessingFieldTypes(true);
  1371. guessFieldTypesXhr = $.post("${ url('indexer:guess_field_types') }", {
  1372. "fileFormat": ko.mapping.toJSON(self.source)
  1373. }, function (resp) {
  1374. resp.columns.forEach(function (entry, i, arr) {
  1375. if (self.destination.outputFormat() === 'table'){
  1376. entry.type = MAPPINGS.get(MAPPINGS.SOLR_TO_HIVE, entry.type, 'string');
  1377. }
  1378. arr[i] = loadField(entry, self.destination, i);
  1379. });
  1380. self.source.sampleCols(resp.sample_cols ? resp.sample_cols : resp.columns);
  1381. self.source.sample(resp.sample);
  1382. self.destination.columns(resp.columns);
  1383. self.isGuessingFieldTypes(false);
  1384. }).fail(function (xhr, textStatus, errorThrown) {
  1385. $(document).trigger("error", xhr.responseText);
  1386. self.isGuessingFieldTypes(false);
  1387. viewModel.isLoading(false);
  1388. });
  1389. };
  1390. self.isIndexing = ko.observable(false);
  1391. self.indexingError = ko.observable(false);
  1392. self.indexingSuccess = ko.observable(false);
  1393. self.indexFile = function () {
  1394. if (! self.readyToIndex()) {
  1395. return;
  1396. }
  1397. %if not is_embeddable:
  1398. self.indexingStarted(true);
  1399. viewModel.isLoading(true);
  1400. self.isIndexing(true);
  1401. $.post("${ url('indexer:importer_submit') }", {
  1402. "source": ko.mapping.toJSON(self.source),
  1403. "destination": ko.mapping.toJSON(self.destination)
  1404. }, function (resp) {
  1405. if (resp.status != 0) {
  1406. $(document).trigger("error", resp.message);
  1407. self.indexingStarted(false);
  1408. self.isIndexing(false);
  1409. } else {
  1410. self.showCreate(true);
  1411. self.editorId(resp.history_id);
  1412. self.jobId(resp.handle.id);
  1413. $('#importerNotebook').html($('#importerNotebook-progress').html());
  1414. self.editorVM = new EditorViewModel(resp.history_uuid, '', {
  1415. user: '${ user.username }',
  1416. userId: ${ user.id },
  1417. languages: [{name: "Java", type: "java"}, {name: "Hive SQL", type: "hive"}], // TODO reuse
  1418. snippetViewSettings: {
  1419. java : {
  1420. snippetIcon: 'fa-file-archive-o '
  1421. },
  1422. hive: {
  1423. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1424. aceMode: 'ace/mode/hive',
  1425. snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
  1426. sqlDialect: true
  1427. },
  1428. impala: {
  1429. placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
  1430. aceMode: 'ace/mode/impala',
  1431. snippetImage: '${ static("impala/art/icon_impala_48.png") }',
  1432. sqlDialect: true
  1433. }
  1434. }
  1435. });
  1436. self.editorVM.editorMode(true);
  1437. self.editorVM.isNotificationManager(true);
  1438. ko.cleanNode($("#importerNotebook")[0]);
  1439. ko.applyBindings(self.editorVM, $("#importerNotebook")[0]);
  1440. self.editorVM.openNotebook(resp.history_uuid, null, true, function(){
  1441. self.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
  1442. if (val == 100){
  1443. self.indexingStarted(false);
  1444. self.isIndexing(false);
  1445. self.indexingSuccess(true);
  1446. }
  1447. });
  1448. self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
  1449. if (val == 'failed'){
  1450. self.isIndexing(false);
  1451. self.indexingStarted(false);
  1452. self.indexingError(true);
  1453. } else if (val == 'available') {
  1454. var snippet = self.editorVM.selectedNotebook().snippets()[0]; // Could be native to editor at some point
  1455. if (! snippet.result.handle().has_more_statements) {
  1456. if (self.editorVM.selectedNotebook().onSuccessUrl()) {
  1457. var match = snippet.statement_raw().match(/CREATE TABLE `([^`]+)`/i);
  1458. if (match) {
  1459. var db = match[1];
  1460. huePubSub.publish('assist.invalidate.impala', { flush: false, database: db });
  1461. }
  1462. huePubSub.publish('assist.clear.db.cache', { sourceType: self.source.apiHelperType() });
  1463. window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
  1464. }
  1465. } else { // Perform last DROP statement execute
  1466. snippet.execute();
  1467. }
  1468. }
  1469. });
  1470. self.editorVM.selectedNotebook().snippets()[0].checkStatus();
  1471. });
  1472. }
  1473. viewModel.isLoading(false);
  1474. }).fail(function (xhr, textStatus, errorThrown) {
  1475. $(document).trigger("error", xhr.responseText);
  1476. viewModel.isLoading(false);
  1477. self.indexingStarted(false);
  1478. self.isIndexing(false);
  1479. });
  1480. % else:
  1481. $.post("${ url('indexer:importer_submit') }", {
  1482. "source": ko.mapping.toJSON(self.source),
  1483. "destination": ko.mapping.toJSON(self.destination),
  1484. "start_time": ko.mapping.toJSON((new Date()).getTime())
  1485. }, function (resp) {
  1486. if (resp.history_uuid) {
  1487. $.jHueNotify.info("${ _('Task ') }" + resp.history_uuid + "${_(' submitted.') }");
  1488. huePubSub.publish('notebook.task.submitted', resp.history_uuid);
  1489. } else {
  1490. $(document).trigger("error", resp && resp.message ? resp.message : '${ _("Error importing") }');
  1491. }
  1492. }).fail(function (xhr, textStatus, errorThrown) {
  1493. $(document).trigger("error", xhr.responseText);
  1494. });
  1495. % endif
  1496. hueAnalytics.log('importer', 'submit/' + self.source.inputFormat() + '/' + self.destination.outputFormat());
  1497. };
  1498. self.removeOperation = function (operation, operationList) {
  1499. operationList.remove(operation);
  1500. hueAnalytics.log('importer', 'step/removeOperation');
  1501. };
  1502. self.addOperation = function (field) {
  1503. field.operations.push(new Operation("split"));
  1504. hueAnalytics.log('importer', 'step/addOperation');
  1505. };
  1506. self.load = function (state) {
  1507. self.source.name(state.name);
  1508. self.source.show(state.show);
  1509. self.source.path(state.path);
  1510. self.destination.columns.removeAll();
  1511. if (state.format && 'type' in state.format) {
  1512. var koFormat = ko.mapping.fromJS(new FileType(state.format.type, state.format));
  1513. self.source.format(koFormat);
  1514. }
  1515. if (state.columns){
  1516. state.columns.forEach(function (currCol) {
  1517. self.destination.columns.push(loadField(currCol));
  1518. });
  1519. }
  1520. }
  1521. };
  1522. var loadDefaultField = function (options) {
  1523. if (! options.name) {
  1524. options.name = getNewFieldName();
  1525. }
  1526. return loadField($.extend({}, ${default_field_type | n}, options));
  1527. };
  1528. var loadField = function (currField, parent, idx) {
  1529. var koField = ko.mapping.fromJS(currField);
  1530. if (koField.name && parent) {
  1531. koField.name.subscribe(function (newVal) {
  1532. if (newVal.indexOf(',') > -1) {
  1533. var fields = newVal.split(',');
  1534. fields.forEach(function (val, i) {
  1535. if (i + idx < parent.columns().length) {
  1536. parent.columns()[i + idx].name(val);
  1537. }
  1538. });
  1539. }
  1540. parent.bulkColumnNames(parent.columns().map(function (item) {
  1541. return item.name()
  1542. }).join(','));
  1543. });
  1544. }
  1545. koField.operations.removeAll();
  1546. currField.operations.forEach(function (operationData) {
  1547. var operation = new Operation(operationData.type);
  1548. operation.load(operationData);
  1549. koField.operations.push(operation);
  1550. });
  1551. var autoExpand = function (newVal) {
  1552. if ((newVal == 'array' || newVal == 'map' || newVal == 'struct') && koField.nested().length == 0) {
  1553. koField.nested.push(loadDefaultField({level: koField.level() + 1}));
  1554. }
  1555. };
  1556. koField.type.subscribe(autoExpand);
  1557. koField.keyType.subscribe(autoExpand);
  1558. return koField;
  1559. };
  1560. var IndexerViewModel = function () {
  1561. var self = this;
  1562. self.apiHelper = ApiHelper.getInstance();
  1563. self.assistAvailable = ko.observable(true);
  1564. self.isLeftPanelVisible = ko.observable();
  1565. self.apiHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
  1566. self.loadDefaultField = loadDefaultField;
  1567. self.createWizard = new CreateWizard(self);
  1568. // Wizard related
  1569. self.wizardEnabled = ko.observable(false);
  1570. self.currentStep = ko.observable(self.createWizard.prefill.target_type() == 'database' ? 2 : 1);
  1571. self.currentStep.subscribe(function () {
  1572. $('.content-panel').scrollTop(0);
  1573. });
  1574. self.previousStepVisible = ko.pureComputed(function(){
  1575. return self.currentStep() > 1 && self.createWizard.destination.outputFormat() != 'database';
  1576. });
  1577. self.nextStepVisible = ko.pureComputed(function(){
  1578. return self.currentStep() < 3 && self.wizardEnabled();
  1579. });
  1580. self.nextStep = function () {
  1581. if (self.nextStepVisible()){
  1582. self.currentStep(self.currentStep() + 1);
  1583. hueAnalytics.log('importer', 'step/' + self.currentStep());
  1584. }
  1585. };
  1586. self.previousStep = function () {
  1587. if (self.previousStepVisible()){
  1588. self.currentStep(self.currentStep() - 1);
  1589. hueAnalytics.log('importer', 'step/' + self.currentStep());
  1590. }
  1591. };
  1592. self.isLoading = ko.observable(false);
  1593. };
  1594. var viewModel;
  1595. function resizeElements () {
  1596. var $contentPanel = $('#importerComponents').find('.content-panel-inner');
  1597. $('.form-actions').width($contentPanel.width() - 50);
  1598. $('.step-indicator-fixed').width($contentPanel.width());
  1599. document.styleSheets[0].addRule('.step-indicator li:first-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()) + 'px');
  1600. document.styleSheets[0].addRule('.step-indicator li:first-child:before','left: ' + ($contentPanel.find('.step-indicator li:first-child .caption').width()/2) + 'px');
  1601. document.styleSheets[0].addRule('.step-indicator li:last-child:before','max-width: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()) + 'px');
  1602. document.styleSheets[0].addRule('.step-indicator li:last-child:before','right: ' + ($contentPanel.find('.step-indicator li:last-child .caption').width()/2) + 'px');
  1603. }
  1604. $(document).ready(function () {
  1605. viewModel = new IndexerViewModel();
  1606. ko.applyBindings(viewModel, $('#importerComponents')[0]);
  1607. var draggableMeta = {};
  1608. huePubSub.subscribe('draggable.text.meta', function (meta) {
  1609. draggableMeta = meta;
  1610. });
  1611. huePubSub.subscribe('split.panel.resized', resizeElements);
  1612. hueUtils.waitForRendered('.step-indicator li:first-child .caption', function(el){ return el.width() < $('#importerComponents').find('.content-panel-inner').width()/2 }, resizeElements);
  1613. $(window).on('resize', resizeElements);
  1614. $('.content-panel').droppable({
  1615. accept: ".draggableText",
  1616. drop: function (e, ui) {
  1617. var text = ui.helper.text();
  1618. var generatedName = 'idx';
  1619. switch (draggableMeta.type){
  1620. case 'sql':
  1621. if (draggableMeta.table !== ''){
  1622. generatedName += draggableMeta.table;
  1623. viewModel.createWizard.source.inputFormat('table');
  1624. viewModel.createWizard.source.table(draggableMeta.table);
  1625. }
  1626. break;
  1627. case 'hdfs':
  1628. generatedName += draggableMeta.definition.name;
  1629. viewModel.createWizard.source.inputFormat('file');
  1630. viewModel.createWizard.source.path(draggableMeta.definition.path);
  1631. break;
  1632. case 'document':
  1633. if (draggableMeta.definition.type === 'query-hive'){
  1634. generatedName += draggableMeta.definition.name;
  1635. viewModel.createWizard.source.inputFormat('query');
  1636. viewModel.createWizard.source.draggedQuery(draggableMeta.definition.uuid);
  1637. }
  1638. break;
  1639. }
  1640. if (generatedName !== 'idx' && viewModel.createWizard.source.name() === ''){
  1641. viewModel.createWizard.source.name(generatedName);
  1642. }
  1643. }
  1644. });
  1645. });
  1646. })();
  1647. </script>
  1648. </span>
  1649. %if not is_embeddable:
  1650. ${ commonfooter(request, messages) | n,unicode }
  1651. %endif