testElasticSearchJoinIndex.ktr 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <transformation>
  3. <info>
  4. <name>testElasticSearchJoinIndex</name>
  5. <description/>
  6. <extended_description/>
  7. <trans_version/>
  8. <trans_type>Normal</trans_type>
  9. <trans_status>0</trans_status>
  10. <directory>/</directory>
  11. <parameters>
  12. </parameters>
  13. <log>
  14. <trans-log-table>
  15. <connection/>
  16. <schema/>
  17. <table/>
  18. <size_limit_lines/>
  19. <interval/>
  20. <timeout_days/>
  21. <field>
  22. <id>ID_BATCH</id>
  23. <enabled>Y</enabled>
  24. <name>ID_BATCH</name>
  25. </field>
  26. <field>
  27. <id>CHANNEL_ID</id>
  28. <enabled>Y</enabled>
  29. <name>CHANNEL_ID</name>
  30. </field>
  31. <field>
  32. <id>TRANSNAME</id>
  33. <enabled>Y</enabled>
  34. <name>TRANSNAME</name>
  35. </field>
  36. <field>
  37. <id>STATUS</id>
  38. <enabled>Y</enabled>
  39. <name>STATUS</name>
  40. </field>
  41. <field>
  42. <id>LINES_READ</id>
  43. <enabled>Y</enabled>
  44. <name>LINES_READ</name>
  45. <subject/>
  46. </field>
  47. <field>
  48. <id>LINES_WRITTEN</id>
  49. <enabled>Y</enabled>
  50. <name>LINES_WRITTEN</name>
  51. <subject/>
  52. </field>
  53. <field>
  54. <id>LINES_UPDATED</id>
  55. <enabled>Y</enabled>
  56. <name>LINES_UPDATED</name>
  57. <subject/>
  58. </field>
  59. <field>
  60. <id>LINES_INPUT</id>
  61. <enabled>Y</enabled>
  62. <name>LINES_INPUT</name>
  63. <subject/>
  64. </field>
  65. <field>
  66. <id>LINES_OUTPUT</id>
  67. <enabled>Y</enabled>
  68. <name>LINES_OUTPUT</name>
  69. <subject/>
  70. </field>
  71. <field>
  72. <id>LINES_REJECTED</id>
  73. <enabled>Y</enabled>
  74. <name>LINES_REJECTED</name>
  75. <subject/>
  76. </field>
  77. <field>
  78. <id>ERRORS</id>
  79. <enabled>Y</enabled>
  80. <name>ERRORS</name>
  81. </field>
  82. <field>
  83. <id>STARTDATE</id>
  84. <enabled>Y</enabled>
  85. <name>STARTDATE</name>
  86. </field>
  87. <field>
  88. <id>ENDDATE</id>
  89. <enabled>Y</enabled>
  90. <name>ENDDATE</name>
  91. </field>
  92. <field>
  93. <id>LOGDATE</id>
  94. <enabled>Y</enabled>
  95. <name>LOGDATE</name>
  96. </field>
  97. <field>
  98. <id>DEPDATE</id>
  99. <enabled>Y</enabled>
  100. <name>DEPDATE</name>
  101. </field>
  102. <field>
  103. <id>REPLAYDATE</id>
  104. <enabled>Y</enabled>
  105. <name>REPLAYDATE</name>
  106. </field>
  107. <field>
  108. <id>LOG_FIELD</id>
  109. <enabled>Y</enabled>
  110. <name>LOG_FIELD</name>
  111. </field>
  112. <field>
  113. <id>EXECUTING_SERVER</id>
  114. <enabled>N</enabled>
  115. <name>EXECUTING_SERVER</name>
  116. </field>
  117. <field>
  118. <id>EXECUTING_USER</id>
  119. <enabled>N</enabled>
  120. <name>EXECUTING_USER</name>
  121. </field>
  122. <field>
  123. <id>CLIENT</id>
  124. <enabled>N</enabled>
  125. <name>CLIENT</name>
  126. </field>
  127. </trans-log-table>
  128. <perf-log-table>
  129. <connection/>
  130. <schema/>
  131. <table/>
  132. <interval/>
  133. <timeout_days/>
  134. <field>
  135. <id>ID_BATCH</id>
  136. <enabled>Y</enabled>
  137. <name>ID_BATCH</name>
  138. </field>
  139. <field>
  140. <id>SEQ_NR</id>
  141. <enabled>Y</enabled>
  142. <name>SEQ_NR</name>
  143. </field>
  144. <field>
  145. <id>LOGDATE</id>
  146. <enabled>Y</enabled>
  147. <name>LOGDATE</name>
  148. </field>
  149. <field>
  150. <id>TRANSNAME</id>
  151. <enabled>Y</enabled>
  152. <name>TRANSNAME</name>
  153. </field>
  154. <field>
  155. <id>STEPNAME</id>
  156. <enabled>Y</enabled>
  157. <name>STEPNAME</name>
  158. </field>
  159. <field>
  160. <id>STEP_COPY</id>
  161. <enabled>Y</enabled>
  162. <name>STEP_COPY</name>
  163. </field>
  164. <field>
  165. <id>LINES_READ</id>
  166. <enabled>Y</enabled>
  167. <name>LINES_READ</name>
  168. </field>
  169. <field>
  170. <id>LINES_WRITTEN</id>
  171. <enabled>Y</enabled>
  172. <name>LINES_WRITTEN</name>
  173. </field>
  174. <field>
  175. <id>LINES_UPDATED</id>
  176. <enabled>Y</enabled>
  177. <name>LINES_UPDATED</name>
  178. </field>
  179. <field>
  180. <id>LINES_INPUT</id>
  181. <enabled>Y</enabled>
  182. <name>LINES_INPUT</name>
  183. </field>
  184. <field>
  185. <id>LINES_OUTPUT</id>
  186. <enabled>Y</enabled>
  187. <name>LINES_OUTPUT</name>
  188. </field>
  189. <field>
  190. <id>LINES_REJECTED</id>
  191. <enabled>Y</enabled>
  192. <name>LINES_REJECTED</name>
  193. </field>
  194. <field>
  195. <id>ERRORS</id>
  196. <enabled>Y</enabled>
  197. <name>ERRORS</name>
  198. </field>
  199. <field>
  200. <id>INPUT_BUFFER_ROWS</id>
  201. <enabled>Y</enabled>
  202. <name>INPUT_BUFFER_ROWS</name>
  203. </field>
  204. <field>
  205. <id>OUTPUT_BUFFER_ROWS</id>
  206. <enabled>Y</enabled>
  207. <name>OUTPUT_BUFFER_ROWS</name>
  208. </field>
  209. </perf-log-table>
  210. <channel-log-table>
  211. <connection/>
  212. <schema/>
  213. <table/>
  214. <timeout_days/>
  215. <field>
  216. <id>ID_BATCH</id>
  217. <enabled>Y</enabled>
  218. <name>ID_BATCH</name>
  219. </field>
  220. <field>
  221. <id>CHANNEL_ID</id>
  222. <enabled>Y</enabled>
  223. <name>CHANNEL_ID</name>
  224. </field>
  225. <field>
  226. <id>LOG_DATE</id>
  227. <enabled>Y</enabled>
  228. <name>LOG_DATE</name>
  229. </field>
  230. <field>
  231. <id>LOGGING_OBJECT_TYPE</id>
  232. <enabled>Y</enabled>
  233. <name>LOGGING_OBJECT_TYPE</name>
  234. </field>
  235. <field>
  236. <id>OBJECT_NAME</id>
  237. <enabled>Y</enabled>
  238. <name>OBJECT_NAME</name>
  239. </field>
  240. <field>
  241. <id>OBJECT_COPY</id>
  242. <enabled>Y</enabled>
  243. <name>OBJECT_COPY</name>
  244. </field>
  245. <field>
  246. <id>REPOSITORY_DIRECTORY</id>
  247. <enabled>Y</enabled>
  248. <name>REPOSITORY_DIRECTORY</name>
  249. </field>
  250. <field>
  251. <id>FILENAME</id>
  252. <enabled>Y</enabled>
  253. <name>FILENAME</name>
  254. </field>
  255. <field>
  256. <id>OBJECT_ID</id>
  257. <enabled>Y</enabled>
  258. <name>OBJECT_ID</name>
  259. </field>
  260. <field>
  261. <id>OBJECT_REVISION</id>
  262. <enabled>Y</enabled>
  263. <name>OBJECT_REVISION</name>
  264. </field>
  265. <field>
  266. <id>PARENT_CHANNEL_ID</id>
  267. <enabled>Y</enabled>
  268. <name>PARENT_CHANNEL_ID</name>
  269. </field>
  270. <field>
  271. <id>ROOT_CHANNEL_ID</id>
  272. <enabled>Y</enabled>
  273. <name>ROOT_CHANNEL_ID</name>
  274. </field>
  275. </channel-log-table>
  276. <step-log-table>
  277. <connection/>
  278. <schema/>
  279. <table/>
  280. <timeout_days/>
  281. <field>
  282. <id>ID_BATCH</id>
  283. <enabled>Y</enabled>
  284. <name>ID_BATCH</name>
  285. </field>
  286. <field>
  287. <id>CHANNEL_ID</id>
  288. <enabled>Y</enabled>
  289. <name>CHANNEL_ID</name>
  290. </field>
  291. <field>
  292. <id>LOG_DATE</id>
  293. <enabled>Y</enabled>
  294. <name>LOG_DATE</name>
  295. </field>
  296. <field>
  297. <id>TRANSNAME</id>
  298. <enabled>Y</enabled>
  299. <name>TRANSNAME</name>
  300. </field>
  301. <field>
  302. <id>STEPNAME</id>
  303. <enabled>Y</enabled>
  304. <name>STEPNAME</name>
  305. </field>
  306. <field>
  307. <id>STEP_COPY</id>
  308. <enabled>Y</enabled>
  309. <name>STEP_COPY</name>
  310. </field>
  311. <field>
  312. <id>LINES_READ</id>
  313. <enabled>Y</enabled>
  314. <name>LINES_READ</name>
  315. </field>
  316. <field>
  317. <id>LINES_WRITTEN</id>
  318. <enabled>Y</enabled>
  319. <name>LINES_WRITTEN</name>
  320. </field>
  321. <field>
  322. <id>LINES_UPDATED</id>
  323. <enabled>Y</enabled>
  324. <name>LINES_UPDATED</name>
  325. </field>
  326. <field>
  327. <id>LINES_INPUT</id>
  328. <enabled>Y</enabled>
  329. <name>LINES_INPUT</name>
  330. </field>
  331. <field>
  332. <id>LINES_OUTPUT</id>
  333. <enabled>Y</enabled>
  334. <name>LINES_OUTPUT</name>
  335. </field>
  336. <field>
  337. <id>LINES_REJECTED</id>
  338. <enabled>Y</enabled>
  339. <name>LINES_REJECTED</name>
  340. </field>
  341. <field>
  342. <id>ERRORS</id>
  343. <enabled>Y</enabled>
  344. <name>ERRORS</name>
  345. </field>
  346. <field>
  347. <id>LOG_FIELD</id>
  348. <enabled>N</enabled>
  349. <name>LOG_FIELD</name>
  350. </field>
  351. </step-log-table>
  352. <metrics-log-table>
  353. <connection/>
  354. <schema/>
  355. <table/>
  356. <timeout_days/>
  357. <field>
  358. <id>ID_BATCH</id>
  359. <enabled>Y</enabled>
  360. <name>ID_BATCH</name>
  361. </field>
  362. <field>
  363. <id>CHANNEL_ID</id>
  364. <enabled>Y</enabled>
  365. <name>CHANNEL_ID</name>
  366. </field>
  367. <field>
  368. <id>LOG_DATE</id>
  369. <enabled>Y</enabled>
  370. <name>LOG_DATE</name>
  371. </field>
  372. <field>
  373. <id>METRICS_DATE</id>
  374. <enabled>Y</enabled>
  375. <name>METRICS_DATE</name>
  376. </field>
  377. <field>
  378. <id>METRICS_CODE</id>
  379. <enabled>Y</enabled>
  380. <name>METRICS_CODE</name>
  381. </field>
  382. <field>
  383. <id>METRICS_DESCRIPTION</id>
  384. <enabled>Y</enabled>
  385. <name>METRICS_DESCRIPTION</name>
  386. </field>
  387. <field>
  388. <id>METRICS_SUBJECT</id>
  389. <enabled>Y</enabled>
  390. <name>METRICS_SUBJECT</name>
  391. </field>
  392. <field>
  393. <id>METRICS_TYPE</id>
  394. <enabled>Y</enabled>
  395. <name>METRICS_TYPE</name>
  396. </field>
  397. <field>
  398. <id>METRICS_VALUE</id>
  399. <enabled>Y</enabled>
  400. <name>METRICS_VALUE</name>
  401. </field>
  402. </metrics-log-table>
  403. </log>
  404. <maxdate>
  405. <connection/>
  406. <table/>
  407. <field/>
  408. <offset>0.0</offset>
  409. <maxdiff>0.0</maxdiff>
  410. </maxdate>
  411. <size_rowset>10000</size_rowset>
  412. <sleep_time_empty>50</sleep_time_empty>
  413. <sleep_time_full>50</sleep_time_full>
  414. <unique_connections>N</unique_connections>
  415. <feedback_shown>Y</feedback_shown>
  416. <feedback_size>50000</feedback_size>
  417. <using_thread_priorities>Y</using_thread_priorities>
  418. <shared_objects_file/>
  419. <capture_step_performance>N</capture_step_performance>
  420. <step_performance_capturing_delay>1000</step_performance_capturing_delay>
  421. <step_performance_capturing_size_limit>100</step_performance_capturing_size_limit>
  422. <dependencies>
  423. </dependencies>
  424. <partitionschemas>
  425. </partitionschemas>
  426. <slaveservers>
  427. </slaveservers>
  428. <clusterschemas>
  429. </clusterschemas>
  430. <created_user>-</created_user>
  431. <created_date>2019/05/17 17:06:44.305</created_date>
  432. <modified_user>-</modified_user>
  433. <modified_date>2019/05/17 17:06:44.305</modified_date>
  434. <key_for_session_key>H4sIAAAAAAAAAAMAAAAAAAAAAAA=</key_for_session_key>
  435. <is_key_private>N</is_key_private>
  436. </info>
  437. <notepads>
  438. </notepads>
  439. <connection>
  440. <name>MemberSqlserver</name>
  441. <server>192.168.50.32</server>
  442. <type>MSSQLNATIVE</type>
  443. <access>Native</access>
  444. <database>MemberData</database>
  445. <port>1433</port>
  446. <username>sa</username>
  447. <password>Encrypted 2be98afc819c69e8ea300ff228dd38f99</password>
  448. <servername/>
  449. <data_tablespace/>
  450. <index_tablespace/>
  451. <attributes>
  452. <attribute>
  453. <code>EXTRA_OPTION_MSSQLNATIVE.instance</code>
  454. <attribute>MemberData</attribute>
  455. </attribute>
  456. <attribute>
  457. <code>FORCE_IDENTIFIERS_TO_LOWERCASE</code>
  458. <attribute>N</attribute>
  459. </attribute>
  460. <attribute>
  461. <code>FORCE_IDENTIFIERS_TO_UPPERCASE</code>
  462. <attribute>N</attribute>
  463. </attribute>
  464. <attribute>
  465. <code>INITIAL_POOL_SIZE</code>
  466. <attribute>100</attribute>
  467. </attribute>
  468. <attribute>
  469. <code>IS_CLUSTERED</code>
  470. <attribute>N</attribute>
  471. </attribute>
  472. <attribute>
  473. <code>MAXIMUM_POOL_SIZE</code>
  474. <attribute>300</attribute>
  475. </attribute>
  476. <attribute>
  477. <code>MSSQLUseIntegratedSecurity</code>
  478. <attribute>false</attribute>
  479. </attribute>
  480. <attribute>
  481. <code>MSSQL_DOUBLE_DECIMAL_SEPARATOR</code>
  482. <attribute>N</attribute>
  483. </attribute>
  484. <attribute>
  485. <code>PORT_NUMBER</code>
  486. <attribute>1433</attribute>
  487. </attribute>
  488. <attribute>
  489. <code>PRESERVE_RESERVED_WORD_CASE</code>
  490. <attribute>Y</attribute>
  491. </attribute>
  492. <attribute>
  493. <code>QUOTE_ALL_FIELDS</code>
  494. <attribute>N</attribute>
  495. </attribute>
  496. <attribute>
  497. <code>SUPPORTS_BOOLEAN_DATA_TYPE</code>
  498. <attribute>Y</attribute>
  499. </attribute>
  500. <attribute>
  501. <code>SUPPORTS_TIMESTAMP_DATA_TYPE</code>
  502. <attribute>Y</attribute>
  503. </attribute>
  504. <attribute>
  505. <code>USE_POOLING</code>
  506. <attribute>Y</attribute>
  507. </attribute>
  508. </attributes>
  509. </connection>
  510. <order>
  511. <hop>
  512. <from>表输入</from>
  513. <to>Java 代码</to>
  514. <enabled>Y</enabled>
  515. </hop>
  516. <hop>
  517. <from>Java 代码</from>
  518. <to>Elasticsearch bulk insert</to>
  519. <enabled>Y</enabled>
  520. </hop>
  521. </order>
  522. <step>
  523. <name>Elasticsearch bulk insert</name>
  524. <type>ElasticSearchBulk</type>
  525. <description/>
  526. <distribute>Y</distribute>
  527. <custom_distribution/>
  528. <copies>1</copies>
  529. <partitioning>
  530. <method>none</method>
  531. <schema_name/>
  532. </partitioning>
  533. <general>
  534. <index>my_index</index>
  535. <type>_doc?routing=2</type>
  536. <batchSize>50000</batchSize>
  537. <timeout>100</timeout>
  538. <timeoutUnit>SECONDS</timeoutUnit>
  539. <isJson>N</isJson>
  540. <idField>id</idField>
  541. <overwriteIfExists>Y</overwriteIfExists>
  542. <useOutput>N</useOutput>
  543. <stopOnError>Y</stopOnError>
  544. </general>
  545. <fields>
  546. <field>
  547. <columnName>id</columnName>
  548. <targetName>id</targetName>
  549. </field>
  550. <field>
  551. <columnName>my_join_field</columnName>
  552. <targetName>my_join_field</targetName>
  553. </field>
  554. <field>
  555. <columnName>text</columnName>
  556. <targetName>text</targetName>
  557. </field>
  558. </fields>
  559. <servers>
  560. <server>
  561. <address>192.168.50.32</address>
  562. <port>9300</port>
  563. </server>
  564. </servers>
  565. <settings>
  566. <setting>
  567. <name>cluster.name</name>
  568. <value>es</value>
  569. </setting>
  570. <setting>
  571. <name>custom.aliase.source</name>
  572. <value>crm_twitter</value>
  573. </setting>
  574. <setting>
  575. <name>custom.fields.date22</name>
  576. <value>{"type":"date","format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||strict_date_optional_time||epoch_millis"}</value>
  577. </setting>
  578. <setting>
  579. <name>custom.fields.twitter</name>
  580. <value>{"type":"text","analyzer": "ik_smart",
  581. "search_analyzer":"ik_smart","index":true}</value>
  582. </setting>
  583. <setting>
  584. <name>custom.index.number_of_replicas</name>
  585. <value>1</value>
  586. </setting>
  587. <setting>
  588. <name>custom.index.number_of_shards</name>
  589. <value>4</value>
  590. </setting>
  591. </settings>
  592. <attributes/>
  593. <cluster_schema/>
  594. <remotesteps>
  595. <input>
  596. </input>
  597. <output>
  598. </output>
  599. </remotesteps>
  600. <GUI>
  601. <xloc>416</xloc>
  602. <yloc>208</yloc>
  603. <draw>Y</draw>
  604. </GUI>
  605. </step>
  606. <step>
  607. <name>Java 代码</name>
  608. <type>UserDefinedJavaClass</type>
  609. <description/>
  610. <distribute>Y</distribute>
  611. <custom_distribution/>
  612. <copies>1</copies>
  613. <partitioning>
  614. <method>none</method>
  615. <schema_name/>
  616. </partitioning>
  617. <definitions>
  618. <definition>
  619. <class_type>TRANSFORM_CLASS</class_type>
  620. <class_name>Processor</class_name>
  621. <class_source>//package com.tools.ws;
  622. //import test.TestFun;
  623. public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException
  624. {
  625. Object[] r = getRow();
  626. // If the row object is null, we are done processing.
  627. if (r == null) {
  628. setOutputDone();
  629. return false;
  630. }
  631. //if(first){
  632. // first = false;
  633. //}
  634. r = createOutputRow(r, data.outputRowMeta.size());
  635. //String inputstr = get(Fields.In,"date").getString(r);
  636. //if(inputstr!=null){
  637. // String tstr = inputstr.replace("-","_");
  638. // get(Fields.Out, "date").setValue(r, tstr);
  639. //}
  640. putRow(data.outputRowMeta, r);
  641. return true;
  642. }</class_source>
  643. </definition>
  644. </definitions>
  645. <fields>
  646. </fields>
  647. <clear_result_fields>N</clear_result_fields>
  648. <info_steps/>
  649. <target_steps/>
  650. <usage_parameters/>
  651. <attributes/>
  652. <cluster_schema/>
  653. <remotesteps>
  654. <input>
  655. </input>
  656. <output>
  657. </output>
  658. </remotesteps>
  659. <GUI>
  660. <xloc>432</xloc>
  661. <yloc>80</yloc>
  662. <draw>Y</draw>
  663. </GUI>
  664. </step>
  665. <step>
  666. <name>表输入</name>
  667. <type>TableInput</type>
  668. <description/>
  669. <distribute>Y</distribute>
  670. <custom_distribution/>
  671. <copies>1</copies>
  672. <partitioning>
  673. <method>none</method>
  674. <schema_name/>
  675. </partitioning>
  676. <connection>MemberSqlserver</connection>
  677. <sql>SELECT
  678. id,
  679. [text]
  680. ,concat('{"name": "answer","parent": "',2,'"}') as my_join_field
  681. FROM my_index
  682. </sql>
  683. <limit>0</limit>
  684. <lookup/>
  685. <execute_each_row>N</execute_each_row>
  686. <variables_active>N</variables_active>
  687. <lazy_conversion_active>N</lazy_conversion_active>
  688. <attributes/>
  689. <cluster_schema/>
  690. <remotesteps>
  691. <input>
  692. </input>
  693. <output>
  694. </output>
  695. </remotesteps>
  696. <GUI>
  697. <xloc>208</xloc>
  698. <yloc>80</yloc>
  699. <draw>Y</draw>
  700. </GUI>
  701. </step>
  702. <step>
  703. <name>Java 代码 2</name>
  704. <type>UserDefinedJavaClass</type>
  705. <description/>
  706. <distribute>Y</distribute>
  707. <custom_distribution/>
  708. <copies>1</copies>
  709. <partitioning>
  710. <method>none</method>
  711. <schema_name/>
  712. </partitioning>
  713. <definitions>
  714. <definition>
  715. <class_type>TRANSFORM_CLASS</class_type>
  716. <class_name>Processor</class_name>
  717. <class_source>
  718. import java.sql.Connection;
  719. import java.sql.DriverManager;
  720. import java.sql.SQLException;
  721. import java.sql.PreparedStatement;
  722. import java.sql.ResultSet;
  723. import java.sql.SQLException;
  724. /**
  725. * 注册数据库驱动
  726. */
  727. static {
  728. try {
  729. Class.forName("com.mysql.jdbc.Driver");
  730. } catch (ClassNotFoundException e) {
  731. e.printStackTrace();
  732. }
  733. }
  734. /**
  735. * 获取数据源
  736. *
  737. * @throws SQLException
  738. */
  739. public static Connection getConnection(String url, String user,
  740. String password) throws SQLException {
  741. return DriverManager.getConnection(url, user, password);
  742. }
  743. /**
  744. * 关闭数据源
  745. *
  746. * @throws SQLException
  747. */
  748. public static void closeConnection(Connection conn) throws SQLException {
  749. if (null != conn) {
  750. conn.close();
  751. }
  752. }
  753. /**
  754. * 判断操作是否成功
  755. */
  756. public static String isSuccess(int count) {
  757. if (count > 0) {
  758. return "操作成功!";
  759. } else {
  760. return "操作失败!";
  761. }
  762. }
  763. /**
  764. * 增加信息
  765. */
  766. public static void saveInfo(Long id,String name,String dataid) {
  767. Connection conn = null;
  768. PreparedStatement ps = null;
  769. try {
  770. conn = getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=Mall",
  771. "sa", "saljhy123!@#");
  772. String sql = "insert into DataImport (id,dataname,dataid) values (?,?,?,?)";
  773. ps = conn.prepareStatement(sql);
  774. ps.setLong(1, id);
  775. ps.setString(2, name);
  776. ps.setString(3, dataid);
  777. int insertCount = ps.executeUpdate();
  778. System.out.println(isSuccess(insertCount));
  779. } catch (Exception e) {
  780. e.printStackTrace();
  781. } finally {
  782. try {
  783. if (null != ps) {
  784. ps.close();
  785. }
  786. if (null != conn) {
  787. conn.close();
  788. }
  789. } catch (Exception e2) {
  790. e2.printStackTrace();
  791. }
  792. }
  793. }
  794. public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
  795. Object[] r = getRow();
  796. if (first) {
  797. first = false;
  798. /* TODO: Your code here. (Using info fields)
  799. */
  800. }
  801. if (r == null) {
  802. setOutputDone();
  803. return false;
  804. }
  805. // It is always safest to call createOutputRow() to ensure that your output row's Object[] is large
  806. // enough to handle any new fields you are creating in this step.
  807. r = createOutputRow(r, data.outputRowMeta.size());
  808. Long id = get(Fields.In,"OrdersCode").getLong(r);
  809. String dataname = "order";
  810. String dataid = get(Fields.In,"OrdersCode").getString(r);
  811. saveInfo(id,dataname,dataid);
  812. /* TODO: Your code here. (See Sample)
  813. // Get the value from an input field
  814. String foobar = get(Fields.In, "a_fieldname").getString(r);
  815. foobar += "bar";
  816. // Set a value in a new output field
  817. get(Fields.Out, "output_fieldname").setValue(r, foobar);
  818. */
  819. // Send the row on to the next step.
  820. putRow(data.outputRowMeta, r);
  821. return true;
  822. }
  823. </class_source>
  824. </definition>
  825. </definitions>
  826. <fields>
  827. </fields>
  828. <clear_result_fields>N</clear_result_fields>
  829. <info_steps/>
  830. <target_steps/>
  831. <usage_parameters/>
  832. <attributes/>
  833. <cluster_schema/>
  834. <remotesteps>
  835. <input>
  836. </input>
  837. <output>
  838. </output>
  839. </remotesteps>
  840. <GUI>
  841. <xloc>794</xloc>
  842. <yloc>114</yloc>
  843. <draw>Y</draw>
  844. </GUI>
  845. </step>
  846. <step_error_handling>
  847. </step_error_handling>
  848. <slave-step-copy-partition-distribution>
  849. </slave-step-copy-partition-distribution>
  850. <slave_transformation>N</slave_transformation>
  851. <attributes/>
  852. </transformation>