BatchWriteRowTest.php 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221
  1. <?php
  2. namespace Aliyun\OTS\Tests;
  3. use Aliyun\OTS;
  4. use Aliyun\OTS\RowExistenceExpectationConst;
  5. use Aliyun\OTS\ComparatorTypeConst;
  6. use Aliyun\OTS\LogicalOperatorConst;
  7. use Aliyun\OTS\ColumnTypeConst;
  8. use Aliyun\OTS\DirectionConst;
  9. require __DIR__ . "/TestBase.php";
  10. require __DIR__ . "/../../../vendor/autoload.php";
  11. $usedTables = array (
  12. "myTable",
  13. "myTable1",
  14. "test1",
  15. "test2",
  16. "test3",
  17. "test4"
  18. );
  19. SDKTestBase::cleanUp ($usedTables);
  20. SDKTestBase::createInitialTable (array (
  21. "table_meta" => array (
  22. "table_name" => $usedTables[0],
  23. "primary_key_schema" => array (
  24. "PK1" => ColumnTypeConst::CONST_INTEGER,
  25. "PK2" => ColumnTypeConst::CONST_STRING
  26. )
  27. ),
  28. "reserved_throughput" => array (
  29. "capacity_unit" => array (
  30. "read" => 0,
  31. "write" => 0
  32. )
  33. )
  34. ));
  35. SDKTestBase::waitForTableReady ();
  36. class BatchWriteRowTest extends SDKTestBase {
  37. /*
  38. *
  39. * GetEmptyBatchWriteRow
  40. * BatchWriteRow没有包含任何表的情况
  41. */
  42. public function testGetEmptyBatchWriteRow() {
  43. $batchWrite = array (
  44. "tables" => array (
  45. array (
  46. "table_name" => 'test9'
  47. )
  48. )
  49. );
  50. try {
  51. $this->otsClient->batchWriteRow ($batchWrite);
  52. $this->fail ('An expected exception has not been raised.');
  53. } catch (\Aliyun\OTS\OTSServerException $exc) {
  54. $c = "No row specified in table: 'test9'.";
  55. $this->assertEquals ($c, $exc->getOTSErrorMessage ());
  56. }
  57. }
  58. /*
  59. * EmptyTableInBatchWriteRow
  60. * BatchWriteRow包含2个表,其中有1个表有1行,另外一个表为空的情况。
  61. */
  62. public function testGetRowWith0ColumsToGet() {
  63. $batchWrite = array (
  64. "tables" => array (
  65. array (
  66. "table_name" => 'test9',
  67. "put_rows" => array (
  68. array (
  69. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  70. "primary_key" => array (
  71. "PK1" => 1,
  72. "PK2" => "a1"
  73. ),
  74. "attribute_columns" => array (
  75. "att1" => "name",
  76. "att2" => 256
  77. )
  78. )
  79. )
  80. ),
  81. array (
  82. "table_name" => 'test8'
  83. )
  84. )
  85. );
  86. try {
  87. $this->otsClient->batchWriteRow ($batchWrite);
  88. $this->fail ('An expected exception has not been raised.');
  89. } catch (\Aliyun\OTS\OTSServerException $exc) {
  90. $c = "No row specified in table: 'test8'.";
  91. $this->assertEquals ($c, $exc->getOTSErrorMessage ());
  92. }
  93. }
  94. /*
  95. * PutOnlyInBatchWriteRow
  96. * BatchWriteRow包含4个Put操作
  97. */
  98. public function testPutOnlyInBatchWriteRow() {
  99. global $usedTables;
  100. $batchWrite = array (
  101. "tables" => array (
  102. array (
  103. "table_name" => $usedTables[0],
  104. "put_rows" => array (
  105. array (
  106. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  107. "primary_key" => array (
  108. "PK1" => 1,
  109. "PK2" => "a1"
  110. ),
  111. "attribute_columns" => array (
  112. "att1" => "name1",
  113. "att2" => 256
  114. )
  115. ),
  116. array (
  117. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  118. "primary_key" => array (
  119. "PK1" => 2,
  120. "PK2" => "a2"
  121. ),
  122. "attribute_columns" => array (
  123. "att1" => "name2",
  124. "att2" => 256
  125. )
  126. ),
  127. array (
  128. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  129. "primary_key" => array (
  130. "PK1" => 3,
  131. "PK2" => "a3"
  132. ),
  133. "attribute_columns" => array (
  134. "att1" => "name3",
  135. "att2" => 256
  136. )
  137. ),
  138. array (
  139. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  140. "primary_key" => array (
  141. "PK1" => 4,
  142. "PK2" => "a4"
  143. ),
  144. "attribute_columns" => array (
  145. "att1" => "name4",
  146. "att2" => 256
  147. )
  148. )
  149. )
  150. )
  151. )
  152. );
  153. // tables
  154. $this->otsClient->batchWriteRow ($batchWrite);
  155. for($i = 1; $i < 5; $i ++) {
  156. $body = array (
  157. "table_name" => $usedTables[0],
  158. "primary_key" => array (
  159. "PK1" => $i,
  160. "PK2" => "a" . $i
  161. ),
  162. "columns_to_get" => array ()
  163. );
  164. $a[] = $this->otsClient->getRow ($body);
  165. }
  166. $this->assertEquals (count ($a), 4);
  167. for($c = 0; $c < count ($a); $c ++) {
  168. $this->assertEquals ($a[$c]['row']['primary_key_columns'], $batchWrite['tables'][0]['put_rows'][$c]['primary_key']);
  169. $this->assertEquals ($a[$c]['row']['attribute_columns'], $batchWrite['tables'][0]['put_rows'][$c]['attribute_columns']);
  170. }
  171. }
  172. /*
  173. * UpdateOnlyInBatchWriteRow
  174. * BatchWriteRow包含4个Update操作
  175. */
  176. public function testUpdateOnlyInBatchWriteRow() {
  177. global $usedTables;
  178. $batchWrite = array (
  179. "tables" => array (
  180. array (
  181. "table_name" => $usedTables[0],
  182. "put_rows" => array (
  183. array (
  184. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  185. "primary_key" => array (
  186. "PK1" => 1,
  187. "PK2" => "a1"
  188. ),
  189. "attribute_columns" => array (
  190. "att1" => "name1",
  191. "att2" => 256
  192. )
  193. ),
  194. array (
  195. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  196. "primary_key" => array (
  197. "PK1" => 2,
  198. "PK2" => "a2"
  199. ),
  200. "attribute_columns" => array (
  201. "att1" => "name2",
  202. "att2" => 256
  203. )
  204. ),
  205. array (
  206. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  207. "primary_key" => array (
  208. "PK1" => 3,
  209. "PK2" => "a3"
  210. ),
  211. "attribute_columns" => array (
  212. "att1" => "name3",
  213. "att2" => 256
  214. )
  215. ),
  216. array (
  217. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  218. "primary_key" => array (
  219. "PK1" => 4,
  220. "PK2" => "a4"
  221. ),
  222. "attribute_columns" => array (
  223. "att1" => "name4",
  224. "att2" => 256
  225. )
  226. )
  227. )
  228. )
  229. )
  230. );
  231. // tables
  232. $this->otsClient->batchWriteRow ($batchWrite);
  233. $batchWrite1 = array (
  234. "tables" => array (
  235. array (
  236. "table_name" => $usedTables[0],
  237. "update_rows" => array (
  238. array (
  239. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  240. "primary_key" => array (
  241. "PK1" => 1,
  242. "PK2" => "a1"
  243. ),
  244. "attribute_columns_to_put" => array (
  245. "att1" => 'Zhon'
  246. ),
  247. "attribute_columns_to_delete" => array (
  248. "att2"
  249. )
  250. ),
  251. array (
  252. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  253. "primary_key" => array (
  254. "PK1" => 2,
  255. "PK2" => "a2"
  256. ),
  257. "attribute_columns_to_put" => array (
  258. "att1" => 'Zhon'
  259. ),
  260. "attribute_columns_to_delete" => array (
  261. "att2"
  262. )
  263. ),
  264. array (
  265. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  266. "primary_key" => array (
  267. "PK1" => 3,
  268. "PK2" => "a3"
  269. ),
  270. "attribute_columns_to_put" => array (
  271. "att1" => 'Zhon'
  272. ),
  273. "attribute_columns_to_delete" => array (
  274. "att2"
  275. )
  276. ),
  277. array (
  278. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  279. "primary_key" => array (
  280. "PK1" => 4,
  281. "PK2" => "a4"
  282. ),
  283. "attribute_columns_to_put" => array (
  284. "att1" => 'Zhon'
  285. ),
  286. "attribute_columns_to_delete" => array (
  287. "att2"
  288. )
  289. )
  290. )
  291. )
  292. )
  293. )
  294. // //////添加多行插入 put_rows
  295. ;
  296. $this->otsClient->batchWriteRow ($batchWrite1);
  297. for($i = 1; $i < 5; $i ++) {
  298. $body = array (
  299. "table_name" => $usedTables[0],
  300. "primary_key" => array (
  301. "PK1" => $i,
  302. "PK2" => "a" . $i
  303. ),
  304. "columns_to_get" => array ()
  305. );
  306. $a[] = $this->otsClient->getRow ($body);
  307. }
  308. $this->assertEquals (count ($a), 4);
  309. for($c = 0; $c < count ($a); $c ++) {
  310. // print_r($a[$c]['row']['primary_key_columns']);
  311. // print_r($batchWrite1['tables'][0]['update_rows'][0]['attribute_columns_to_put']);
  312. $this->assertEquals ($a[$c]['row']['primary_key_columns'], $batchWrite['tables'][0]['put_rows'][$c]['primary_key']);
  313. $this->assertEquals ($a[$c]['row']['attribute_columns'], $batchWrite1['tables'][0]['update_rows'][$c]['attribute_columns_to_put']);
  314. }
  315. }
  316. /*
  317. * DeleteOnlyInBatchWriteRow
  318. * BatchWriteRow包含4个Delete操作
  319. */
  320. public function testDeleteOnlyInBatchWriteRow() {
  321. global $usedTables;
  322. $batchWrite = array (
  323. "tables" => array (
  324. array (
  325. "table_name" => $usedTables[0],
  326. "put_rows" => array (
  327. array (
  328. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  329. "primary_key" => array (
  330. "PK1" => 1,
  331. "PK2" => "a1"
  332. ),
  333. "attribute_columns" => array (
  334. "att1" => "name1",
  335. "att2" => -256.66
  336. )
  337. ),
  338. array (
  339. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  340. "primary_key" => array (
  341. "PK1" => 2,
  342. "PK2" => "a2"
  343. ),
  344. "attribute_columns" => array (
  345. "att1" => "name2",
  346. "att2" => -256.66
  347. )
  348. ),
  349. array (
  350. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  351. "primary_key" => array (
  352. "PK1" => 3,
  353. "PK2" => "a3"
  354. ),
  355. "attribute_columns" => array (
  356. "att1" => "name3",
  357. "att2" => -256.66
  358. )
  359. ),
  360. array (
  361. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  362. "primary_key" => array (
  363. "PK1" => 4,
  364. "PK2" => "a4"
  365. ),
  366. "attribute_columns" => array (
  367. "att1" => "name4",
  368. "att2" => -256.66
  369. )
  370. )
  371. )
  372. )
  373. )
  374. );
  375. // tables
  376. $this->otsClient->batchWriteRow ($batchWrite);
  377. $batchWrite1 = array (
  378. "tables" => array (
  379. array (
  380. "table_name" => $usedTables[0],
  381. "delete_rows" => array (
  382. array (
  383. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  384. "primary_key" => array (
  385. "PK1" => 1,
  386. "PK2" => "a1"
  387. )
  388. ),
  389. array (
  390. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  391. "primary_key" => array (
  392. "PK1" => 2,
  393. "PK2" => "a2"
  394. )
  395. ),
  396. array (
  397. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  398. "primary_key" => array (
  399. "PK1" => 3,
  400. "PK2" => "a3"
  401. )
  402. ),
  403. array (
  404. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  405. "primary_key" => array (
  406. "PK1" => 4,
  407. "PK2" => "a4"
  408. )
  409. )
  410. )
  411. )
  412. )
  413. )
  414. // //////添加多行插入 put_rows
  415. ;
  416. $getrow = $this->otsClient->batchWriteRow ($batchWrite1);
  417. for($i = 1; $i < 5; $i ++) {
  418. $body = array (
  419. "table_name" => $usedTables[0],
  420. "primary_key" => array (
  421. "PK1" => $i,
  422. "PK2" => "a" . $i
  423. ),
  424. "columns_to_get" => array ('att2')
  425. );
  426. $a[] = $this->otsClient->getRow ($body);
  427. }
  428. $this->assertEquals (count ($a), 4);
  429. for($c = 0; $c < count ($a); $c ++) {
  430. $this->assertEmpty ($a[$c]['row']['primary_key_columns']);
  431. $this->assertEmpty ($a[$c]['row']['attribute_columns']);
  432. }
  433. }
  434. /*
  435. * 4PutUpdateDeleteInBatchWriteRow
  436. * BatchWriteRow同时包含4个Put,4个Update和4个Delete操作
  437. */
  438. public function testPutUpdateDeleteInBatchWriteRow() {
  439. global $usedTables;
  440. for($i = 1; $i < 9; $i ++) {
  441. $put[] = array (
  442. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  443. "primary_key" => array (
  444. "PK1" => $i,
  445. "PK2" => "a" . $i
  446. ),
  447. "attribute_columns" => array (
  448. "att1" => "name{$i}",
  449. "att2" => 256
  450. )
  451. );
  452. }
  453. $batchWrite = array (
  454. "tables" => array (
  455. array (
  456. "table_name" => $usedTables[0],
  457. "put_rows" => $put
  458. )
  459. )
  460. );
  461. // tables
  462. $this->otsClient->batchWriteRow ($batchWrite);
  463. $batchWrite1 = array (
  464. "tables" => array (
  465. array (
  466. "table_name" => $usedTables[0],
  467. "put_rows" => array (
  468. array (
  469. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  470. "primary_key" => array (
  471. "PK1" => 9,
  472. "PK2" => "a9"
  473. ),
  474. "attribute_columns" => array (
  475. "att1" => "name",
  476. "att2" => 256
  477. )
  478. ),
  479. array (
  480. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  481. "primary_key" => array (
  482. "PK1" => 10,
  483. "PK2" => "a10"
  484. ),
  485. "attribute_columns" => array (
  486. "att1" => "name",
  487. "att2" => 256
  488. )
  489. ),
  490. array (
  491. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  492. "primary_key" => array (
  493. "PK1" => 11,
  494. "PK2" => "a11"
  495. ),
  496. "attribute_columns" => array (
  497. "att1" => "name",
  498. "att2" => 256
  499. )
  500. ),
  501. array (
  502. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  503. "primary_key" => array (
  504. "PK1" => 12,
  505. "PK2" => "a12"
  506. ),
  507. "attribute_columns" => array (
  508. "att1" => "name",
  509. "att2" => 256
  510. )
  511. )
  512. ),
  513. // //////添加多行插入 put_rows
  514. "update_rows" => array (
  515. array (
  516. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  517. "primary_key" => array (
  518. "PK1" => 5,
  519. "PK2" => "a5"
  520. ),
  521. "attribute_columns_to_put" => array (
  522. "att1" => 'Zhon'
  523. ),
  524. "attribute_columns_to_delete" => array (
  525. "att2"
  526. )
  527. ),
  528. array (
  529. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  530. "primary_key" => array (
  531. "PK1" => 6,
  532. "PK2" => "a6"
  533. ),
  534. "attribute_columns_to_put" => array (
  535. "att1" => 'Zhon'
  536. ),
  537. "attribute_columns_to_delete" => array (
  538. "att2"
  539. )
  540. ),
  541. array (
  542. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  543. "primary_key" => array (
  544. "PK1" => 7,
  545. "PK2" => "a7"
  546. ),
  547. "attribute_columns_to_put" => array (
  548. "att1" => 'Zhon'
  549. ),
  550. "attribute_columns_to_delete" => array (
  551. "att2"
  552. )
  553. ),
  554. array (
  555. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  556. "primary_key" => array (
  557. "PK1" => 8,
  558. "PK2" => "a8"
  559. ),
  560. "attribute_columns_to_put" => array (
  561. "att1" => 'Zhon'
  562. ),
  563. "attribute_columns_to_delete" => array (
  564. "att2"
  565. )
  566. )
  567. ),
  568. "delete_rows" => array (
  569. array (
  570. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  571. "primary_key" => array (
  572. "PK1" => 1,
  573. "PK2" => "a1"
  574. )
  575. ),
  576. array (
  577. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  578. "primary_key" => array (
  579. "PK1" => 2,
  580. "PK2" => "a2"
  581. )
  582. ),
  583. array (
  584. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  585. "primary_key" => array (
  586. "PK1" => 3,
  587. "PK2" => "a3"
  588. )
  589. ),
  590. array (
  591. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  592. "primary_key" => array (
  593. "PK1" => 4,
  594. "PK2" => "a4"
  595. )
  596. )
  597. )
  598. )
  599. )
  600. );
  601. $getrow = $this->otsClient->batchWriteRow ($batchWrite1);
  602. $getRange = array (
  603. "table_name" => $usedTables[0],
  604. "direction" => DirectionConst::CONST_FORWARD,
  605. "columns_to_get" => array (),
  606. "limit" => 100,
  607. "inclusive_start_primary_key" => array (
  608. "PK1" => 1,
  609. "PK2" => "a1"
  610. ),
  611. "exclusive_end_primary_key" => array (
  612. "PK1" => 30,
  613. "PK2" => "a30"
  614. )
  615. );
  616. $a = $this->otsClient->getRange ($getRange);
  617. $this->assertEquals (count ($a['rows']), 8);
  618. for($i = 0; $i < count ($a['rows']); $i ++) {
  619. $row = $a['rows'][$i];
  620. $pk1 = $row['primary_key_columns']['PK1'];
  621. $columns = $row['attribute_columns'];
  622. $this->assertEquals ($pk1, $i + 5);
  623. // 1-4 rows deleted
  624. if ($pk1 >= 5 && $pk1 <= 8) {
  625. // 5-8 rows updated
  626. $this->assertEquals ($columns['att1'], 'Zhon');
  627. } elseif ($pk1 >= 9 && $pk1 <= 12) {
  628. // 9-12 rows put
  629. $this->assertEquals ($columns['att1'], 'name');
  630. $this->assertEquals ($columns['att2'], 256);
  631. } else {
  632. $this->fail ("Deleted rows read.");
  633. }
  634. }
  635. }
  636. /*
  637. * 1000PutUpdateDeleteInBatchWriteRow
  638. * BatchWriteRow同时包含1000个Put,4个Update和4个Delete操作,期望返回服务端错误
  639. */
  640. public function testPut1000UpdateDeleteInBatchWriteRow() {
  641. global $usedTables;
  642. for($i = 1; $i < 1000; $i ++) {
  643. $a[] = array (
  644. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  645. "primary_key" => array (
  646. "PK1" => $i,
  647. "PK2" => "a" . $i
  648. ),
  649. "attribute_columns" => array (
  650. "att1" => "name",
  651. "att2" => 256
  652. )
  653. );
  654. }
  655. // print_r($a);die;
  656. $batchWrite = array (
  657. "tables" => array (
  658. array (
  659. "table_name" => $usedTables[0],
  660. "put_rows" => $a,
  661. "update_rows" => array (
  662. array (
  663. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  664. "primary_key" => array (
  665. "PK1" => 5,
  666. "PK2" => "a5"
  667. ),
  668. "attribute_columns" => array (
  669. array (
  670. "att1" => 'Zhon',
  671. "type" => "PUT"
  672. ),
  673. array (
  674. "att2" => 256,
  675. "type" => "DELETE"
  676. )
  677. )
  678. ),
  679. array (
  680. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  681. "primary_key" => array (
  682. "PK1" => 6,
  683. "PK2" => "a6"
  684. ),
  685. "attribute_columns" => array (
  686. array (
  687. "att1" => 'Zhon',
  688. "type" => "PUT"
  689. ),
  690. array (
  691. "att2" => 256,
  692. "type" => "DELETE"
  693. )
  694. )
  695. ),
  696. array (
  697. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  698. "primary_key" => array (
  699. "PK1" => 7,
  700. "PK2" => "a7"
  701. ),
  702. "attribute_columns" => array (
  703. array (
  704. "att1" => 'Zhon',
  705. "type" => "PUT"
  706. ),
  707. array (
  708. "att2" => 256,
  709. "type" => "DELETE"
  710. )
  711. )
  712. ),
  713. array (
  714. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  715. "primary_key" => array (
  716. "PK1" => 8,
  717. "PK2" => "a8"
  718. ),
  719. "attribute_columns" => array (
  720. array (
  721. "att1" => 'Zhon',
  722. "type" => "PUT"
  723. ),
  724. array (
  725. "att2" => 256,
  726. "type" => "DELETE"
  727. )
  728. )
  729. )
  730. ),
  731. "delete_rows" => array (
  732. array (
  733. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  734. "primary_key" => array (
  735. "PK1" => 1,
  736. "PK2" => "a1"
  737. )
  738. ),
  739. array (
  740. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  741. "primary_key" => array (
  742. "PK1" => 2,
  743. "PK2" => "a2"
  744. )
  745. ),
  746. array (
  747. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  748. "primary_key" => array (
  749. "PK1" => 3,
  750. "PK2" => "a3"
  751. )
  752. ),
  753. array (
  754. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  755. "primary_key" => array (
  756. "PK1" => 4,
  757. "PK2" => "a4"
  758. )
  759. )
  760. )
  761. )
  762. )
  763. );
  764. try {
  765. $this->otsClient->batchWriteRow ($batchWrite);
  766. $this->fail ('An expected exception has not been raised.');
  767. } catch (\Aliyun\OTS\OTSServerException $exc) {
  768. $c = "Rows count exceeds the upper limit";
  769. $this->assertEquals ($c, $exc->getOTSErrorMessage ());
  770. }
  771. }
  772. /*
  773. * 4TablesInBatchWriteRow
  774. * BatchWriteRow包含4个表的情况。
  775. */
  776. public function testTables4InBatchWriteRow() {
  777. for($i = 1; $i < 5; $i ++) {
  778. $tablebody = array (
  779. "table_meta" => array (
  780. "table_name" => "test" . $i,
  781. "primary_key_schema" => array (
  782. "PK1" => ColumnTypeConst::CONST_INTEGER,
  783. "PK2" => ColumnTypeConst::CONST_STRING
  784. )
  785. ),
  786. "reserved_throughput" => array (
  787. "capacity_unit" => array (
  788. "read" => 0,
  789. "write" => 0
  790. )
  791. )
  792. );
  793. $this->otsClient->createTable ($tablebody);
  794. }
  795. $this->waitForTableReady ();
  796. $batchWrite = array (
  797. "tables" => array (
  798. array (
  799. "table_name" => 'test1',
  800. "put_rows" => array (
  801. array (
  802. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  803. "primary_key" => array (
  804. "PK1" => 1,
  805. "PK2" => "a1"
  806. ),
  807. "attribute_columns" => array (
  808. "att1" => "name",
  809. "att2" => 256
  810. )
  811. )
  812. )
  813. ),
  814. array (
  815. "table_name" => 'test2',
  816. "put_rows" => array (
  817. array (
  818. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  819. "primary_key" => array (
  820. "PK1" => 1,
  821. "PK2" => "a1"
  822. ),
  823. "attribute_columns" => array (
  824. "att1" => "name",
  825. "att2" => 256
  826. )
  827. )
  828. )
  829. ),
  830. array (
  831. "table_name" => 'test3',
  832. "put_rows" => array (
  833. array (
  834. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  835. "primary_key" => array (
  836. "PK1" => 1,
  837. "PK2" => "a1"
  838. ),
  839. "attribute_columns" => array (
  840. "att1" => "name",
  841. "att2" => 256
  842. )
  843. )
  844. )
  845. ),
  846. array (
  847. "table_name" => 'test4',
  848. "put_rows" => array (
  849. array (
  850. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  851. "primary_key" => array (
  852. "PK1" => 1,
  853. "PK2" => "a1"
  854. ),
  855. "attribute_columns" => array (
  856. "att1" => "name",
  857. "att2" => 256
  858. )
  859. )
  860. )
  861. )
  862. )
  863. );
  864. $this->otsClient->batchWriteRow ($batchWrite);
  865. for($i = 1; $i < 5; $i ++) {
  866. $body = array (
  867. "table_name" => "test" . $i,
  868. "primary_key" => array (
  869. "PK1" => 1,
  870. "PK2" => "a1"
  871. ),
  872. "columns_to_get" => array ()
  873. );
  874. $getrow[] = $this->otsClient->getRow ($body);
  875. }
  876. $primary = array (
  877. "PK1" => 1,
  878. "PK2" => "a1"
  879. );
  880. $columns = array (
  881. "att1" => "name",
  882. "att2" => 256
  883. );
  884. $this->assertEquals (count ($getrow), 4);
  885. for($i = 0; $i < count ($getrow); $i ++) {
  886. $this->assertEquals ($getrow[$i]['row']['primary_key_columns'], $primary);
  887. $this->assertEquals ($getrow[$i]['row']['attribute_columns'], $columns);
  888. }
  889. }
  890. /*
  891. * OneTableOneFailInBatchWriteRow
  892. * BatchWriteRow有一个表中的一行失败的情况
  893. */
  894. public function testOneTableOneFailInBatchWriteRow() {
  895. global $usedTables;
  896. $batchWrite = array (
  897. "tables" => array (
  898. array (
  899. "table_name" => $usedTables[0],
  900. "put_rows" => array (
  901. array (
  902. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  903. "primary_key" => array (
  904. "PK1" => 9,
  905. "PK2" => "a9"
  906. ),
  907. "attribute_columns" => array (
  908. "att1" => "name",
  909. "att2" => 256
  910. )
  911. ),
  912. array (
  913. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  914. "primary_key" => array (
  915. "PK1" => 10,
  916. "PK2" => "a10"
  917. ),
  918. "attribute_columns" => array (
  919. "att1" => "name",
  920. "att2" => 256
  921. )
  922. )
  923. ),
  924. // //////添加多行插入 put_rows
  925. "update_rows" => array (
  926. array (
  927. "condition" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  928. "primary_key" => array (
  929. "PK1" => 510,
  930. "PK2" => "a510"
  931. ),
  932. "attribute_columns_to_put" => array (
  933. "att1" => 'Zhon'
  934. ),
  935. "attribute_columns_to_delete" => array (
  936. "att2"
  937. )
  938. ),
  939. array (
  940. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  941. "primary_key" => array (
  942. "PK1" => 6,
  943. "PK2" => "a6"
  944. ),
  945. "attribute_columns_to_put" => array (
  946. "att1" => 'Zhon'
  947. ),
  948. "attribute_columns_to_delete" => array (
  949. "att2"
  950. )
  951. )
  952. ),
  953. "delete_rows" => array (
  954. array (
  955. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  956. "primary_key" => array (
  957. "PK1" => 11,
  958. "PK2" => "a11"
  959. )
  960. ),
  961. array (
  962. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  963. "primary_key" => array (
  964. "PK1" => 12,
  965. "PK2" => "a12"
  966. )
  967. )
  968. )
  969. )
  970. )
  971. );
  972. $writerow = $this->otsClient->batchWriteRow ($batchWrite);
  973. $this->assertEquals ($writerow['tables'][0]['update_rows'][0]['is_ok'], 0);
  974. $this->assertEquals ($writerow['tables'][0]['update_rows'][0]['error'], array (
  975. "code" => "OTSConditionCheckFail",
  976. "message" => "Condition check failed."
  977. ));
  978. }
  979. /*
  980. * OneTableTwoFailInBatchWriteRow
  981. * BatchWriteRow有一个表中的二行失败的情况
  982. */
  983. public function testOneTableTwoFailInBatchWriteRow() {
  984. global $usedTables;
  985. $pkOfRows = array (
  986. array (
  987. "PK1" => 9,
  988. "PK2" => "a9"
  989. ),
  990. array (
  991. "PK1" => 10,
  992. "PK2" => "a10"
  993. ),
  994. array (
  995. "PK1" => 510,
  996. "PK2" => "a510"
  997. ),
  998. array (
  999. "PK1" => 6,
  1000. "PK2" => "a6"
  1001. ),
  1002. array (
  1003. "PK1" => 11,
  1004. "PK2" => "a11"
  1005. ),
  1006. array (
  1007. "PK1" => 12,
  1008. "PK2" => "a12"
  1009. )
  1010. );
  1011. foreach ($pkOfRows as $pk) {
  1012. $this->otsClient->deleteRow (array (
  1013. "table_name" => $usedTables[0],
  1014. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1015. "primary_key" => $pk
  1016. ));
  1017. }
  1018. $batchWrite = array (
  1019. "tables" => array (
  1020. array (
  1021. "table_name" => $usedTables[0],
  1022. "put_rows" => array (
  1023. array (
  1024. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1025. "primary_key" => array (
  1026. "PK1" => 9,
  1027. "PK2" => "a9"
  1028. ),
  1029. "attribute_columns" => array (
  1030. "att1" => "name",
  1031. "att2" => 256
  1032. )
  1033. ),
  1034. array (
  1035. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1036. "primary_key" => array (
  1037. "PK1" => 10,
  1038. "PK2" => "a10"
  1039. ),
  1040. "attribute_columns" => array (
  1041. "att1" => "name",
  1042. "att2" => 256
  1043. )
  1044. )
  1045. ),
  1046. // //////添加多行插入 put_rows
  1047. "update_rows" => array (
  1048. array (
  1049. "condition" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1050. "primary_key" => array (
  1051. "PK1" => 510,
  1052. "PK2" => "a510"
  1053. ),
  1054. "attribute_columns_to_put" => array (
  1055. "att1" => 'Zhon'
  1056. ),
  1057. "attribute_columns_to_delete" => array (
  1058. "att2"
  1059. )
  1060. ),
  1061. array (
  1062. "condition" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1063. "primary_key" => array (
  1064. "PK1" => 6,
  1065. "PK2" => "a6"
  1066. ),
  1067. "attribute_columns_to_put" => array (
  1068. "att1" => 'Zhon'
  1069. ),
  1070. "attribute_columns_to_delete" => array (
  1071. "att2"
  1072. )
  1073. )
  1074. ),
  1075. "delete_rows" => array (
  1076. array (
  1077. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1078. "primary_key" => array (
  1079. "PK1" => 11,
  1080. "PK2" => "a11"
  1081. )
  1082. ),
  1083. array (
  1084. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1085. "primary_key" => array (
  1086. "PK1" => 12,
  1087. "PK2" => "a12"
  1088. )
  1089. )
  1090. )
  1091. )
  1092. )
  1093. );
  1094. $writerow = $this->otsClient->batchWriteRow ($batchWrite);
  1095. $this->assertEquals ($writerow['tables'][0]['update_rows'][0]['is_ok'], 0);
  1096. $this->assertEquals ($writerow['tables'][0]['update_rows'][1]['is_ok'], 0);
  1097. $this->assertEquals ($writerow['tables'][0]['update_rows'][0]['error'], array (
  1098. "code" => "OTSConditionCheckFail",
  1099. "message" => "Condition check failed."
  1100. ));
  1101. $this->assertEquals ($writerow['tables'][0]['update_rows'][1]['error'], array (
  1102. "code" => "OTSConditionCheckFail",
  1103. "message" => "Condition check failed."
  1104. ));
  1105. }
  1106. /*
  1107. * TwoTableOneFailInBatchWriteRow
  1108. * BatchWriteRow有2个表各有1行失败的情况
  1109. */
  1110. public function testTwoTableOneFailInBatchWriteRow() {
  1111. global $usedTables;
  1112. $tablebody = array (
  1113. "table_meta" => array (
  1114. "table_name" => $usedTables[1],
  1115. "primary_key_schema" => array (
  1116. "PK1" => ColumnTypeConst::CONST_INTEGER,
  1117. "PK2" => ColumnTypeConst::CONST_STRING
  1118. )
  1119. ),
  1120. "reserved_throughput" => array (
  1121. "capacity_unit" => array (
  1122. "read" => 0,
  1123. "write" => 0
  1124. )
  1125. )
  1126. );
  1127. $this->otsClient->createTable ($tablebody);
  1128. $this->waitForTableReady ();
  1129. $batchWrite = array (
  1130. "tables" => array (
  1131. array (
  1132. "table_name" => $usedTables[0],
  1133. "put_rows" => array (
  1134. array (
  1135. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1136. "primary_key" => array (
  1137. "PK1" => 9,
  1138. "PK2" => "a9"
  1139. ),
  1140. "attribute_columns" => array (
  1141. "att1" => "name",
  1142. "att2" => 256
  1143. )
  1144. )
  1145. ),
  1146. // //////添加多行插入 put_rows
  1147. "update_rows" => array (
  1148. array (
  1149. "condition" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1150. "primary_key" => array (
  1151. "PK1" => 510,
  1152. "PK2" => "a510"
  1153. ),
  1154. "attribute_columns_to_put" => array (
  1155. "att1" => 'Zhon'
  1156. ),
  1157. "attribute_columns_to_delete" => array (
  1158. "att2"
  1159. )
  1160. )
  1161. ),
  1162. "delete_rows" => array (
  1163. array (
  1164. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1165. "primary_key" => array (
  1166. "PK1" => 11,
  1167. "PK2" => "a11"
  1168. )
  1169. )
  1170. )
  1171. ),
  1172. array (
  1173. "table_name" => $usedTables[1],
  1174. "put_rows" => array (
  1175. array (
  1176. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1177. "primary_key" => array (
  1178. "PK1" => 9,
  1179. "PK2" => "a9"
  1180. ),
  1181. "attribute_columns" => array (
  1182. "att1" => "name",
  1183. "att2" => 256
  1184. )
  1185. )
  1186. ),
  1187. // //////添加多行插入 put_rows
  1188. "update_rows" => array (
  1189. array (
  1190. "condition" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1191. "primary_key" => array (
  1192. "PK1" => 510,
  1193. "PK2" => "a510"
  1194. ),
  1195. "attribute_columns_to_put" => array (
  1196. "att1" => 'Zhon'
  1197. ),
  1198. "attribute_columns_to_delete" => array (
  1199. "att2"
  1200. )
  1201. )
  1202. ),
  1203. "delete_rows" => array (
  1204. array (
  1205. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1206. "primary_key" => array (
  1207. "PK1" => 11,
  1208. "PK2" => "a11"
  1209. )
  1210. )
  1211. )
  1212. )
  1213. )
  1214. );
  1215. $writerow = $this->otsClient->batchWriteRow ($batchWrite);
  1216. // print_r($writerow);die;
  1217. $this->assertEquals ($writerow['tables'][0]['update_rows'][0]['is_ok'], 0);
  1218. $this->assertEquals ($writerow['tables'][1]['update_rows'][0]['is_ok'], 0);
  1219. $this->assertEquals ($writerow['tables'][0]['update_rows'][0]['error'], array (
  1220. "code" => "OTSConditionCheckFail",
  1221. "message" => "Condition check failed."
  1222. ));
  1223. $this->assertEquals ($writerow['tables'][1]['update_rows'][0]['error'], array (
  1224. "code" => "OTSConditionCheckFail",
  1225. "message" => "Condition check failed."
  1226. ));
  1227. }
  1228. /*
  1229. * 1000TablesInBatchWriteRow
  1230. * BatchWriteRow包含1000个表的情况,期望返回服务端错误
  1231. */
  1232. public function testP1000TablesInBatchWriteRow() {
  1233. for($i = 1; $i < 1001; $i ++) {
  1234. $res[] = array (
  1235. "table_name" => 'test' . $i,
  1236. "put_rows" => array (
  1237. array (
  1238. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1239. "primary_key" => array (
  1240. "PK1" => 1,
  1241. "PK2" => "a1"
  1242. ),
  1243. "attribute_columns" => array (
  1244. "att1" => "name",
  1245. "att2" => 256
  1246. )
  1247. )
  1248. )
  1249. );
  1250. }
  1251. $batchWrite = array (
  1252. "tables" => $res
  1253. );
  1254. try {
  1255. $this->otsClient->batchWriteRow ($batchWrite);
  1256. $this->fail ('An expected exception has not been raised.');
  1257. } catch (\Aliyun\OTS\OTSServerException $exc) {
  1258. $c = "Rows count exceeds the upper limit";
  1259. $this->assertEquals ($c, $exc->getOTSErrorMessage ());
  1260. }
  1261. }
  1262. /**
  1263. * 测试在单表上使用单一ColumnCondition的过滤条件下,使用BatchWriteRow接口进行批量写入操作是否成功。
  1264. */
  1265. public function testBatchWriteRowWithSingleColumnConditionAndSingleTable() {
  1266. // To prepare the environment.
  1267. global $usedTables;
  1268. $tables = $this->otsClient->listTable (array ());
  1269. for($i = 0; $i < 2; ++ $i) {
  1270. if (! in_array ($usedTables[$i], $tables)) {
  1271. $tablemeta = array (
  1272. "table_meta" => array (
  1273. "table_name" => $usedTables[$i],
  1274. "primary_key_schema" => array (
  1275. "PK1" => ColumnTypeConst::CONST_INTEGER,
  1276. "PK2" => ColumnTypeConst::CONST_STRING
  1277. )
  1278. ),
  1279. "reserved_throughput" => array (
  1280. "capacity_unit" => array (
  1281. "read" => 0,
  1282. "write" => 0
  1283. )
  1284. )
  1285. );
  1286. $this->otsClient->createTable ($tablemeta);
  1287. $this->waitForTableReady ();
  1288. }
  1289. for($k = 1; $k < 100; ++ $k) {
  1290. $putdata = array (
  1291. "table_name" => $usedTables[$i],
  1292. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1293. "primary_key" => array (
  1294. "PK1" => $k,
  1295. "PK2" => "a" . $k
  1296. ),
  1297. "attribute_columns" => array (
  1298. "attr1" => $k,
  1299. "attr2" => "aa",
  1300. "attr3" => "tas",
  1301. "attr4" => $k . "-" . $k
  1302. )
  1303. );
  1304. $this->otsClient->putRow ($putdata);
  1305. }
  1306. }
  1307. $this->waitForTableReady ();
  1308. // begin testing
  1309. $batchWriteData = array (
  1310. "tables" => array (
  1311. array (
  1312. "table_name" => $usedTables[0],
  1313. "put_rows" => array (
  1314. array (
  1315. "condition" => array (
  1316. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1317. "column_filter" => array (
  1318. "column_name" => "attr1",
  1319. "value" => 19,
  1320. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1321. )
  1322. ),
  1323. "primary_key" => array (
  1324. "PK1" => 19,
  1325. "PK2" => "a19"
  1326. ),
  1327. "attribute_columns" => array (
  1328. "attr1" => 109,
  1329. "attr2" => "aa109"
  1330. )
  1331. )
  1332. ),
  1333. // //////添加多行插入 put_rows
  1334. "update_rows" => array (
  1335. array (
  1336. "condition" => array (
  1337. "row_existence" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1338. "column_filter" => array (
  1339. "column_name" => "attr1",
  1340. "value" => 99,
  1341. "comparator" => ComparatorTypeConst::CONST_GREATER_EQUAL
  1342. )
  1343. ),
  1344. "primary_key" => array (
  1345. "PK1" => 99,
  1346. "PK2" => "a99"
  1347. ),
  1348. "attribute_columns_to_put" => array (
  1349. "attr1" => 990
  1350. ),
  1351. "attribute_columns_to_delete" => array (
  1352. "attr2"
  1353. )
  1354. )
  1355. ),
  1356. "delete_rows" => array (
  1357. array (
  1358. "condition" => array (
  1359. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1360. "column_filter" => array (
  1361. "column_name" => "attr2",
  1362. "value" => "ab",
  1363. "comparator" => ComparatorTypeConst::CONST_LESS_EQUAL
  1364. )
  1365. ),
  1366. "primary_key" => array (
  1367. "PK1" => 11,
  1368. "PK2" => "a11"
  1369. )
  1370. )
  1371. )
  1372. )
  1373. )
  1374. );
  1375. $this->otsClient->batchWriteRow ($batchWriteData);
  1376. $batchGetQuery = array (
  1377. "tables" => array (
  1378. array (
  1379. "table_name" => $usedTables[0],
  1380. "columns_to_get" => array (
  1381. "attr1",
  1382. "attr2"
  1383. ),
  1384. "rows" => array (
  1385. array (
  1386. "primary_key" => array (
  1387. "PK1" => 19,
  1388. "PK2" => "a19"
  1389. )
  1390. ),
  1391. array (
  1392. "primary_key" => array (
  1393. "PK1" => 99,
  1394. "PK2" => "a99"
  1395. )
  1396. ),
  1397. array (
  1398. "primary_key" => array (
  1399. "PK1" => 11,
  1400. "PK2" => "a11"
  1401. )
  1402. )
  1403. )
  1404. )
  1405. )
  1406. );
  1407. $batchGetRes = $this->otsClient->batchGetRow ($batchGetQuery);
  1408. $this->assertEquals (count ($batchGetRes['tables'][0]['rows']), 3);
  1409. for($i = 0; $i < count ($batchGetRes['tables'][0]['rows']); $i ++) {
  1410. $this->assertEquals ($batchGetRes['tables'][0]['rows'][$i]['is_ok'], 1);
  1411. }
  1412. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr1'], 109);
  1413. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr2'], "aa109");
  1414. $this->assertEquals ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr1'], 990);
  1415. $this->assertFalse (isset ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr2']));
  1416. $this->assertEquals (count ($batchGetRes['tables'][0]['rows'][2]['row']['attribute_columns']), 0);
  1417. }
  1418. /**
  1419. * 测试在单表中使用多重ColumnCondition的过滤条件下,使用BatchWriteRow接口进行批量写入操作是否成功。
  1420. */
  1421. public function testBatchWriteRowWithMultipleColumnConditionsAndSingleTables() {
  1422. // To prepare the environment.
  1423. global $usedTables;
  1424. $tables = $this->otsClient->listTable (array ());
  1425. for($i = 0; $i < 2; ++ $i) {
  1426. if (in_array ($usedTables[$i], $tables)) {
  1427. $this->otsClient->deleteTable (array (
  1428. "table_name" => $usedTables[$i]
  1429. ));
  1430. }
  1431. $tablemeta = array (
  1432. "table_meta" => array (
  1433. "table_name" => $usedTables[$i],
  1434. "primary_key_schema" => array (
  1435. "PK1" => ColumnTypeConst::CONST_INTEGER,
  1436. "PK2" => ColumnTypeConst::CONST_STRING
  1437. )
  1438. ),
  1439. "reserved_throughput" => array (
  1440. "capacity_unit" => array (
  1441. "read" => 0,
  1442. "write" => 0
  1443. )
  1444. )
  1445. );
  1446. $this->otsClient->createTable ($tablemeta);
  1447. $this->waitForTableReady ();
  1448. for($k = 1; $k < 100; ++ $k) {
  1449. $putdata = array (
  1450. "table_name" => $usedTables[$i],
  1451. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1452. "primary_key" => array (
  1453. "PK1" => $k,
  1454. "PK2" => "a" . $k
  1455. ),
  1456. "attribute_columns" => array (
  1457. "attr1" => $k,
  1458. "attr2" => "aa",
  1459. "attr3" => "tas",
  1460. "attr4" => $k . "-" . $k
  1461. )
  1462. );
  1463. $this->otsClient->putRow ($putdata);
  1464. }
  1465. }
  1466. // begin testing
  1467. $batchWriteData = array (
  1468. "tables" => array (
  1469. array (
  1470. "table_name" => $usedTables[0],
  1471. "put_rows" => array (
  1472. array (
  1473. "condition" => array (
  1474. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1475. "column_filter" => array (
  1476. "logical_operator" => LogicalOperatorConst::CONST_NOT,
  1477. "sub_conditions" => array (
  1478. array (
  1479. "column_name" => "attr1",
  1480. "value" => 19,
  1481. "comparator" => ComparatorTypeConst::CONST_NOT_EQUAL
  1482. )
  1483. )
  1484. )
  1485. ),
  1486. "primary_key" => array (
  1487. "PK1" => 19,
  1488. "PK2" => "a19"
  1489. ),
  1490. "attribute_columns" => array (
  1491. "attr1" => 109,
  1492. "attr2" => "aa109"
  1493. )
  1494. )
  1495. ),
  1496. // //////添加多行插入 put_rows
  1497. "update_rows" => array (
  1498. array (
  1499. "condition" => array (
  1500. "row_existence" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1501. "column_filter" => array (
  1502. "logical_operator" => LogicalOperatorConst::CONST_AND,
  1503. "sub_conditions" => array (
  1504. array (
  1505. "column_name" => "attr1",
  1506. "value" => 99,
  1507. "comparator" => ComparatorTypeConst::CONST_GREATER_EQUAL
  1508. ),
  1509. array (
  1510. "logical_operator" => LogicalOperatorConst::CONST_OR,
  1511. "sub_conditions" => array (
  1512. array (
  1513. "column_name" => "attr2",
  1514. "value" => "aa",
  1515. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1516. ),
  1517. array (
  1518. "column_name" => "attr2",
  1519. "value" => "ddddd",
  1520. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1521. )
  1522. )
  1523. )
  1524. )
  1525. )
  1526. ),
  1527. "primary_key" => array (
  1528. "PK1" => 99,
  1529. "PK2" => "a99"
  1530. ),
  1531. "attribute_columns_to_put" => array (
  1532. "attr1" => 990
  1533. ),
  1534. "attribute_columns_to_delete" => array (
  1535. "attr2"
  1536. )
  1537. )
  1538. ),
  1539. "delete_rows" => array (
  1540. array (
  1541. "condition" => array (
  1542. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1543. "column_filter" => array (
  1544. "column_name" => "attr2",
  1545. "value" => "ab",
  1546. "comparator" => ComparatorTypeConst::CONST_LESS_EQUAL
  1547. )
  1548. ),
  1549. "primary_key" => array (
  1550. "PK1" => 11,
  1551. "PK2" => "a11"
  1552. )
  1553. )
  1554. )
  1555. )
  1556. )
  1557. );
  1558. $this->otsClient->batchWriteRow ($batchWriteData);
  1559. $batchGetQuery = array (
  1560. "tables" => array (
  1561. array (
  1562. "table_name" => $usedTables[0],
  1563. "columns_to_get" => array (
  1564. "attr1",
  1565. "attr2"
  1566. ),
  1567. "rows" => array (
  1568. array (
  1569. "primary_key" => array (
  1570. "PK1" => 19,
  1571. "PK2" => "a19"
  1572. )
  1573. ),
  1574. array (
  1575. "primary_key" => array (
  1576. "PK1" => 99,
  1577. "PK2" => "a99"
  1578. )
  1579. ),
  1580. array (
  1581. "primary_key" => array (
  1582. "PK1" => 11,
  1583. "PK2" => "a11"
  1584. )
  1585. )
  1586. )
  1587. )
  1588. )
  1589. );
  1590. $batchGetRes = $this->otsClient->batchGetRow ($batchGetQuery);
  1591. $this->assertEquals (count ($batchGetRes['tables'][0]['rows']), 3);
  1592. for($i = 0; $i < count ($batchGetRes['tables'][0]['rows']); $i ++) {
  1593. $this->assertEquals ($batchGetRes['tables'][0]['rows'][$i]['is_ok'], 1);
  1594. }
  1595. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr1'], 109);
  1596. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr2'], "aa109");
  1597. $this->assertEquals ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr1'], 990);
  1598. $this->assertFalse (isset ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr2']));
  1599. $this->assertEquals (count ($batchGetRes['tables'][0]['rows'][2]['row']['attribute_columns']), 0);
  1600. }
  1601. /**
  1602. * 测试在多表中和单一ColumnCondition的过滤条件下,使用BatchWriteRow接口进行批量写入的操作是否成功。
  1603. */
  1604. public function testBatchWriteRowWithSingleColumnConditionAndMultipleTables() {
  1605. // To prepare the environment.
  1606. global $usedTables;
  1607. $tables = $this->otsClient->listTable (array ());
  1608. for($i = 0; $i < 2; ++ $i) {
  1609. if (! in_array ($usedTables[$i], $tables)) {
  1610. $tablemeta = array (
  1611. "table_meta" => array (
  1612. "table_name" => $usedTables[$i],
  1613. "primary_key_schema" => array (
  1614. "PK1" => ColumnTypeConst::CONST_INTEGER,
  1615. "PK2" => ColumnTypeConst::CONST_STRING
  1616. )
  1617. ),
  1618. "reserved_throughput" => array (
  1619. "capacity_unit" => array (
  1620. "read" => 0,
  1621. "write" => 0
  1622. )
  1623. )
  1624. );
  1625. $this->otsClient->createTable ($tablemeta);
  1626. $this->waitForTableReady ();
  1627. }
  1628. for($k = 1; $k < 100; ++ $k) {
  1629. $putdata = array (
  1630. "table_name" => $usedTables[$i],
  1631. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1632. "primary_key" => array (
  1633. "PK1" => $k,
  1634. "PK2" => "a" . $k
  1635. ),
  1636. "attribute_columns" => array (
  1637. "attr1" => $k,
  1638. "attr2" => "aa",
  1639. "attr3" => "tas",
  1640. "attr4" => $k . "-" . $k
  1641. )
  1642. );
  1643. $this->otsClient->putRow ($putdata);
  1644. }
  1645. }
  1646. // begin testing
  1647. $batchWriteData = array (
  1648. "tables" => array (
  1649. array (
  1650. "table_name" => $usedTables[0],
  1651. "put_rows" => array (
  1652. array (
  1653. "condition" => array (
  1654. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1655. "column_filter" => array (
  1656. "column_name" => "attr1",
  1657. "value" => 19,
  1658. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1659. )
  1660. ),
  1661. "primary_key" => array (
  1662. "PK1" => 19,
  1663. "PK2" => "a19"
  1664. ),
  1665. "attribute_columns" => array (
  1666. "attr1" => 109,
  1667. "attr2" => "aa109"
  1668. )
  1669. )
  1670. ),
  1671. // //////添加多行插入 put_rows
  1672. "update_rows" => array (
  1673. array (
  1674. "condition" => array (
  1675. "row_existence" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1676. "column_filter" => array (
  1677. "column_name" => "attr1",
  1678. "value" => 99,
  1679. "comparator" => ComparatorTypeConst::CONST_GREATER_EQUAL
  1680. )
  1681. ),
  1682. "primary_key" => array (
  1683. "PK1" => 99,
  1684. "PK2" => "a99"
  1685. ),
  1686. "attribute_columns_to_put" => array (
  1687. "attr1" => 990
  1688. ),
  1689. "attribute_columns_to_delete" => array (
  1690. "attr2"
  1691. )
  1692. )
  1693. ),
  1694. "delete_rows" => array (
  1695. array (
  1696. "condition" => array (
  1697. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1698. "column_filter" => array (
  1699. "column_name" => "attr2",
  1700. "value" => "ab",
  1701. "comparator" => ComparatorTypeConst::CONST_LESS_EQUAL
  1702. )
  1703. ),
  1704. "primary_key" => array (
  1705. "PK1" => 11,
  1706. "PK2" => "a11"
  1707. )
  1708. )
  1709. )
  1710. ),
  1711. array (
  1712. "table_name" => $usedTables[1],
  1713. "put_rows" => array (
  1714. array (
  1715. "condition" => array (
  1716. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE
  1717. ),
  1718. "primary_key" => array (
  1719. "PK1" => 119,
  1720. "PK2" => "a119"
  1721. ),
  1722. "attribute_columns" => array (
  1723. "attr1" => 119,
  1724. "attr2" => "aa119"
  1725. )
  1726. )
  1727. ),
  1728. // //////添加多行插入 put_rows
  1729. "update_rows" => array (
  1730. array (
  1731. "condition" => array (
  1732. "row_existence" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1733. "column_filter" => array (
  1734. "logical_operator" => LogicalOperatorConst::CONST_AND,
  1735. "sub_conditions" => array (
  1736. array (
  1737. "column_name" => "attr1",
  1738. "value" => 10,
  1739. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1740. ),
  1741. array (
  1742. "column_name" => "attr2",
  1743. "value" => "aa",
  1744. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1745. )
  1746. )
  1747. )
  1748. ),
  1749. "primary_key" => array (
  1750. "PK1" => 10,
  1751. "PK2" => "a10"
  1752. ),
  1753. "attribute_columns_to_put" => array (
  1754. "attr1" => 1000
  1755. ),
  1756. "attribute_columns_to_delete" => array (
  1757. "attr2"
  1758. )
  1759. )
  1760. ),
  1761. "delete_rows" => array (
  1762. array (
  1763. "condition" => array (
  1764. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1765. "column_filter" => array (
  1766. "logical_operator" => LogicalOperatorConst::CONST_OR,
  1767. "sub_conditions" => array (
  1768. array (
  1769. "column_name" => "attr1",
  1770. "value" => 11,
  1771. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1772. ),
  1773. array (
  1774. "column_name" => "attr2",
  1775. "value" => "aabbb",
  1776. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1777. )
  1778. )
  1779. )
  1780. ),
  1781. "primary_key" => array (
  1782. "PK1" => 11,
  1783. "PK2" => "a11"
  1784. )
  1785. )
  1786. )
  1787. )
  1788. )
  1789. );
  1790. $this->otsClient->batchWriteRow ($batchWriteData);
  1791. $batchGetQuery = array (
  1792. "tables" => array (
  1793. array (
  1794. "table_name" => $usedTables[0],
  1795. "columns_to_get" => array (
  1796. "attr1",
  1797. "attr2"
  1798. ),
  1799. "rows" => array (
  1800. array (
  1801. "primary_key" => array (
  1802. "PK1" => 19,
  1803. "PK2" => "a19"
  1804. )
  1805. ),
  1806. array (
  1807. "primary_key" => array (
  1808. "PK1" => 99,
  1809. "PK2" => "a99"
  1810. )
  1811. ),
  1812. array (
  1813. "primary_key" => array (
  1814. "PK1" => 11,
  1815. "PK2" => "a11"
  1816. )
  1817. )
  1818. )
  1819. ),
  1820. array (
  1821. "table_name" => $usedTables[1],
  1822. "columns_to_get" => array (
  1823. "attr1",
  1824. "attr2"
  1825. ),
  1826. "rows" => array (
  1827. array (
  1828. "primary_key" => array (
  1829. "PK1" => 119,
  1830. "PK2" => "a119"
  1831. )
  1832. ),
  1833. array (
  1834. "primary_key" => array (
  1835. "PK1" => 10,
  1836. "PK2" => "a10"
  1837. )
  1838. ),
  1839. array (
  1840. "primary_key" => array (
  1841. "PK1" => 11,
  1842. "PK2" => "a11"
  1843. )
  1844. )
  1845. )
  1846. )
  1847. )
  1848. );
  1849. $batchGetRes = $this->otsClient->batchGetRow ($batchGetQuery);
  1850. // to verify the first updated table
  1851. $this->assertEquals (count ($batchGetRes['tables'][0]['rows']), 3);
  1852. for($i = 0; $i < count ($batchGetRes['tables'][0]['rows']); $i ++) {
  1853. $this->assertEquals ($batchGetRes['tables'][0]['rows'][$i]['is_ok'], 1);
  1854. }
  1855. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr1'], 109);
  1856. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr2'], "aa109");
  1857. $this->assertEquals ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr1'], 990);
  1858. $this->assertFalse (isset ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr2']));
  1859. $this->assertEquals (count ($batchGetRes['tables'][0]['rows'][2]['row']['attribute_columns']), 0);
  1860. // to verify the second updated table
  1861. $this->assertEquals (count ($batchGetRes['tables'][1]['rows']), 3);
  1862. for($i = 0; $i < count ($batchGetRes['tables'][1]['rows']); $i ++) {
  1863. $this->assertEquals ($batchGetRes['tables'][1]['rows'][$i]['is_ok'], 1);
  1864. }
  1865. $this->assertEquals ($batchGetRes['tables'][1]['rows'][0]['row']['attribute_columns']['attr1'], 119);
  1866. $this->assertEquals ($batchGetRes['tables'][1]['rows'][0]['row']['attribute_columns']['attr2'], "aa119");
  1867. $this->assertEquals ($batchGetRes['tables'][1]['rows'][1]['row']['attribute_columns']['attr1'], 1000);
  1868. $this->assertFalse (isset ($batchGetRes['tables'][1]['rows'][1]['row']['attribute_columns']['attr2']));
  1869. $this->assertEquals (count ($batchGetRes['tables'][1]['rows'][2]['row']['attribute_columns']), 0);
  1870. }
  1871. /**
  1872. * 测试在多表中使用多重ColumnCondition过滤条件下,使用BatchWriteRow接口进行批量写入是否成功。
  1873. */
  1874. public function testBatchWriteRowWithMultipleColumnConditionsAndMultipleTables() {
  1875. // To prepare the environment.
  1876. global $usedTables;
  1877. $tables = $this->otsClient->listTable (array ());
  1878. for($i = 0; $i < 2; ++ $i) {
  1879. if (in_array ($usedTables[$i], $tables)) {
  1880. $this->otsClient->deleteTable (array (
  1881. "table_name" => $usedTables[$i]
  1882. ));
  1883. }
  1884. $tablemeta = array (
  1885. "table_meta" => array (
  1886. "table_name" => $usedTables[$i],
  1887. "primary_key_schema" => array (
  1888. "PK1" => ColumnTypeConst::CONST_INTEGER,
  1889. "PK2" => ColumnTypeConst::CONST_STRING
  1890. )
  1891. ),
  1892. "reserved_throughput" => array (
  1893. "capacity_unit" => array (
  1894. "read" => 0,
  1895. "write" => 0
  1896. )
  1897. )
  1898. );
  1899. $this->otsClient->createTable ($tablemeta);
  1900. $this->waitForTableReady ();
  1901. for($k = 1; $k < 100; ++ $k) {
  1902. $putdata = array (
  1903. "table_name" => $usedTables[$i],
  1904. "condition" => RowExistenceExpectationConst::CONST_IGNORE,
  1905. "primary_key" => array (
  1906. "PK1" => $k,
  1907. "PK2" => "a" . $k
  1908. ),
  1909. "attribute_columns" => array (
  1910. "attr1" => $k,
  1911. "attr2" => "aa",
  1912. "attr3" => "tas",
  1913. "attr4" => $k . "-" . $k
  1914. )
  1915. );
  1916. $this->otsClient->putRow ($putdata);
  1917. }
  1918. }
  1919. // begin testing
  1920. $batchWriteData = array (
  1921. "tables" => array (
  1922. array (
  1923. "table_name" => $usedTables[0],
  1924. "put_rows" => array (
  1925. array (
  1926. "condition" => array (
  1927. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1928. "column_filter" => array (
  1929. "logical_operator" => LogicalOperatorConst::CONST_NOT,
  1930. "sub_conditions" => array (
  1931. array (
  1932. "column_name" => "attr1",
  1933. "value" => 19,
  1934. "comparator" => ComparatorTypeConst::CONST_NOT_EQUAL
  1935. )
  1936. )
  1937. )
  1938. ),
  1939. "primary_key" => array (
  1940. "PK1" => 19,
  1941. "PK2" => "a19"
  1942. ),
  1943. "attribute_columns" => array (
  1944. "attr1" => 109,
  1945. "attr2" => "aa109"
  1946. )
  1947. )
  1948. ),
  1949. // //////添加多行插入 put_rows
  1950. "update_rows" => array (
  1951. array (
  1952. "condition" => array (
  1953. "row_existence" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  1954. "column_filter" => array (
  1955. "logical_operator" => LogicalOperatorConst::CONST_AND,
  1956. "sub_conditions" => array (
  1957. array (
  1958. "column_name" => "attr1",
  1959. "value" => 99,
  1960. "comparator" => ComparatorTypeConst::CONST_GREATER_EQUAL
  1961. ),
  1962. array (
  1963. "logical_operator" => LogicalOperatorConst::CONST_OR,
  1964. "sub_conditions" => array (
  1965. array (
  1966. "column_name" => "attr2",
  1967. "value" => "aa",
  1968. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1969. ),
  1970. array (
  1971. "column_name" => "attr2",
  1972. "value" => "ddddd",
  1973. "comparator" => ComparatorTypeConst::CONST_EQUAL
  1974. )
  1975. )
  1976. )
  1977. )
  1978. )
  1979. ),
  1980. "primary_key" => array (
  1981. "PK1" => 99,
  1982. "PK2" => "a99"
  1983. ),
  1984. "attribute_columns_to_put" => array (
  1985. "attr1" => 990
  1986. ),
  1987. "attribute_columns_to_delete" => array (
  1988. "attr2"
  1989. )
  1990. )
  1991. ),
  1992. "delete_rows" => array (
  1993. array (
  1994. "condition" => array (
  1995. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  1996. "column_filter" => array (
  1997. "column_name" => "attr2",
  1998. "value" => "ab",
  1999. "comparator" => ComparatorTypeConst::CONST_LESS_EQUAL
  2000. )
  2001. ),
  2002. "primary_key" => array (
  2003. "PK1" => 11,
  2004. "PK2" => "a11"
  2005. )
  2006. )
  2007. )
  2008. ),
  2009. array (
  2010. "table_name" => $usedTables[1],
  2011. "put_rows" => array (
  2012. array (
  2013. "condition" => array (
  2014. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE
  2015. ),
  2016. "primary_key" => array (
  2017. "PK1" => 119,
  2018. "PK2" => "a119"
  2019. ),
  2020. "attribute_columns" => array (
  2021. "attr1" => 119,
  2022. "attr2" => "aa119"
  2023. )
  2024. )
  2025. ),
  2026. // //////添加多行插入 put_rows
  2027. "update_rows" => array (
  2028. array (
  2029. "condition" => array (
  2030. "row_existence" => RowExistenceExpectationConst::CONST_EXPECT_EXIST,
  2031. "column_filter" => array (
  2032. "logical_operator" => LogicalOperatorConst::CONST_AND,
  2033. "sub_conditions" => array (
  2034. array (
  2035. "column_name" => "attr1",
  2036. "value" => 10,
  2037. "comparator" => ComparatorTypeConst::CONST_EQUAL
  2038. ),
  2039. array (
  2040. "column_name" => "attr2",
  2041. "value" => "aa",
  2042. "comparator" => ComparatorTypeConst::CONST_EQUAL
  2043. )
  2044. )
  2045. )
  2046. ),
  2047. "primary_key" => array (
  2048. "PK1" => 10,
  2049. "PK2" => "a10"
  2050. ),
  2051. "attribute_columns_to_put" => array (
  2052. "attr1" => 1000
  2053. ),
  2054. "attribute_columns_to_delete" => array (
  2055. "attr2"
  2056. )
  2057. )
  2058. ),
  2059. "delete_rows" => array (
  2060. array (
  2061. "condition" => array (
  2062. "row_existence" => RowExistenceExpectationConst::CONST_IGNORE,
  2063. "column_filter" => array (
  2064. "logical_operator" => LogicalOperatorConst::CONST_OR,
  2065. "sub_conditions" => array (
  2066. array (
  2067. "column_name" => "attr1",
  2068. "value" => 11,
  2069. "comparator" => ComparatorTypeConst::CONST_EQUAL
  2070. ),
  2071. array (
  2072. "column_name" => "attr2",
  2073. "value" => "aabbb",
  2074. "comparator" => ComparatorTypeConst::CONST_EQUAL
  2075. )
  2076. )
  2077. )
  2078. ),
  2079. "primary_key" => array (
  2080. "PK1" => 11,
  2081. "PK2" => "a11"
  2082. )
  2083. )
  2084. )
  2085. )
  2086. )
  2087. );
  2088. $this->otsClient->batchWriteRow ($batchWriteData);
  2089. $batchGetQuery = array (
  2090. "tables" => array (
  2091. array (
  2092. "table_name" => $usedTables[0],
  2093. "columns_to_get" => array (
  2094. "attr1",
  2095. "attr2"
  2096. ),
  2097. "rows" => array (
  2098. array (
  2099. "primary_key" => array (
  2100. "PK1" => 19,
  2101. "PK2" => "a19"
  2102. )
  2103. ),
  2104. array (
  2105. "primary_key" => array (
  2106. "PK1" => 99,
  2107. "PK2" => "a99"
  2108. )
  2109. ),
  2110. array (
  2111. "primary_key" => array (
  2112. "PK1" => 11,
  2113. "PK2" => "a11"
  2114. )
  2115. )
  2116. )
  2117. ),
  2118. array (
  2119. "table_name" => $usedTables[1],
  2120. "columns_to_get" => array (
  2121. "attr1",
  2122. "attr2"
  2123. ),
  2124. "rows" => array (
  2125. array (
  2126. "primary_key" => array (
  2127. "PK1" => 119,
  2128. "PK2" => "a119"
  2129. )
  2130. ),
  2131. array (
  2132. "primary_key" => array (
  2133. "PK1" => 10,
  2134. "PK2" => "a10"
  2135. )
  2136. ),
  2137. array (
  2138. "primary_key" => array (
  2139. "PK1" => 11,
  2140. "PK2" => "a11"
  2141. )
  2142. )
  2143. )
  2144. )
  2145. )
  2146. );
  2147. $batchGetRes = $this->otsClient->batchGetRow ($batchGetQuery);
  2148. // to verify the first updated table
  2149. $this->assertEquals (count ($batchGetRes['tables'][0]['rows']), 3);
  2150. for($i = 0; $i < count ($batchGetRes['tables'][0]['rows']); $i ++) {
  2151. $this->assertEquals ($batchGetRes['tables'][0]['rows'][$i]['is_ok'], 1);
  2152. }
  2153. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr1'], 109);
  2154. $this->assertEquals ($batchGetRes['tables'][0]['rows'][0]['row']['attribute_columns']['attr2'], "aa109");
  2155. $this->assertEquals ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr1'], 990);
  2156. $this->assertFalse (isset ($batchGetRes['tables'][0]['rows'][1]['row']['attribute_columns']['attr2']));
  2157. $this->assertEquals (count ($batchGetRes['tables'][0]['rows'][2]['row']['attribute_columns']), 0);
  2158. // to verify the second updated table
  2159. $this->assertEquals (count ($batchGetRes['tables'][1]['rows']), 3);
  2160. for($i = 0; $i < count ($batchGetRes['tables'][1]['rows']); $i ++) {
  2161. $this->assertEquals ($batchGetRes['tables'][1]['rows'][$i]['is_ok'], 1);
  2162. }
  2163. $this->assertEquals ($batchGetRes['tables'][1]['rows'][0]['row']['attribute_columns']['attr1'], 119);
  2164. $this->assertEquals ($batchGetRes['tables'][1]['rows'][0]['row']['attribute_columns']['attr2'], "aa119");
  2165. $this->assertEquals ($batchGetRes['tables'][1]['rows'][1]['row']['attribute_columns']['attr1'], 1000);
  2166. $this->assertFalse (isset ($batchGetRes['tables'][1]['rows'][1]['row']['attribute_columns']['attr2']));
  2167. $this->assertEquals ( count ( $batchGetRes ['tables'] [1] ['rows'] [2] ['row'] ['attribute_columns'] ), 0 );
  2168. }
  2169. }