PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/test/e2e/pig/tests/macro.conf

https://github.com/dorefiend/pig
Unknown | 614 lines | 560 code | 54 blank | 0 comment | 0 complexity | d5906a9e5c81aa6fd0a84b227ad62fcb MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. ###############################################################################
  18. # Nightly tests for pig.
  19. #
  20. # Author: Alan F. Gates (gates@)
  21. # $Header:$
  22. #
  23. #use Yahoo::Miners::Test::PigSetup;
  24. #PigSetup::setup();
  25. #my $me = `whoami`;
  26. #chomp $me;
  27. $cfg = {
  28. 'driver' => 'Pig',
  29. 'groups' => [
  30. {
  31. 'name' => 'Macro_DefinitionAndInline',
  32. 'tests' => [
  33. {
  34. # simple macro, no args
  35. 'num' => 1,
  36. 'pig' => q#define simple_macro() returns void {
  37. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  38. b = foreach a generate age, name;
  39. store b into ':OUTPATH:';
  40. }
  41. simple_macro();#,
  42. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  43. b = foreach a generate age, name;
  44. store b into ':OUTPATH:';#,
  45. },{
  46. # input args, no return
  47. 'num' => 2,
  48. 'pig' => q#define simple_macro(loadfile) returns void {
  49. a = load '$loadfile' as (name, age, gpa);
  50. b = foreach a generate age, name;
  51. store b into ':OUTPATH:';
  52. }
  53. simple_macro(':INPATH:/singlefile/studenttab10k');#,
  54. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  55. b = foreach a generate age, name;
  56. store b into ':OUTPATH:';#,
  57. },{
  58. # input args, return value
  59. 'num' => 3,
  60. 'pig' => q#define simple_macro(loadfile) returns b {
  61. a = load '$loadfile' as (name, age, gpa);
  62. $b = foreach a generate age, name;
  63. }
  64. x = simple_macro(':INPATH:/singlefile/studenttab10k');
  65. store x into ':OUTPATH:';#,
  66. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  67. b = foreach a generate age, name;
  68. store b into ':OUTPATH:';#,
  69. },
  70. {
  71. # input args, filter on double and int, return value
  72. 'num' => 4,
  73. 'pig' => q#define simple_macro(in_relation, min_gpa, max_age) returns c {
  74. b = filter $in_relation by gpa >= $min_gpa and age <= $max_age;
  75. $c = foreach b generate age, name;
  76. }
  77. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  78. x = simple_macro(a, '3.0', '40');
  79. store x into ':OUTPATH:';#,
  80. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  81. b = filter a by gpa >= 3.0 and age <= 40;
  82. c = foreach b generate age, name;
  83. store c into ':OUTPATH:';#,
  84. },
  85. {
  86. #Definition multiple input, no output, multiple returns value
  87. #x = with multiple input, no output, multiple returns value
  88. #Query based on FilterEq from nightly.conf
  89. 'num' => 5,
  90. 'pig' => q\define test (in1, in2) returns r1, r2 {
  91. a = load '$in1' using PigStorage() as (name, age, gpa);
  92. $r1 = filter a by (age >= 50 or name > 'fred') and (gpa <= 3.0 or name >= 'bob');
  93. b = load '$in2' using PigStorage() as (name:chararray, age:int, registration, contributions:double);
  94. $r2 = filter b by name matches 'f.ed' and (chararray)registration matches 'd.m';
  95. }
  96. x1, x2 = test(':INPATH:/singlefile/studenttab10k', ':INPATH:/singlefile/votertab10k');
  97. store x1 into ':OUTPATH:.1' using PigStorage;
  98. store x2 into ':OUTPATH:.2' using PigStorage;\,
  99. 'verify_pig_script' => q\a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  100. a1 = filter a by (age >= 50 or name > 'fred') and (gpa <= 3.0 or name >= 'bob');
  101. store a1 into ':OUTPATH:.1' using PigStorage;
  102. b = load ':INPATH:/singlefile/votertab10k' using PigStorage() as (name:chararray, age:int, registration, contributions:double);
  103. b2 = filter b by name matches 'f.ed' and (chararray)registration matches 'd.m';
  104. store b2 into ':OUTPATH:.2' using PigStorage;\,
  105. 'floatpostprocess' => 1,
  106. 'delimiter' => ' ',
  107. },
  108. {
  109. # use positional parameters inside macro
  110. 'num' => 6,
  111. 'pig' => q#define simple_macro(in_relation, min_gpa, max_age) returns c {
  112. b = filter $in_relation by $2 >= $min_gpa and $1 <= $max_age;
  113. $c = foreach b generate age, name;
  114. }
  115. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  116. x = simple_macro(a, '3.0', '40');
  117. store x into ':OUTPATH:';#,
  118. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  119. b = filter a by gpa >= 3.0 and age <= 40;
  120. c = foreach b generate age, name;
  121. store c into ':OUTPATH:';#,
  122. },
  123. {
  124. # Test nested macros
  125. 'num' => 7,
  126. 'pig' => q\define sum_it(in, relation, scol) returns d {
  127. $d = foreach $in generate group, SUM($relation.$scol);
  128. }
  129. define group_it(in_relation, group_key, sum_col) returns c {
  130. b = group $in_relation by $group_key ;
  131. $c = sum_it(b, $in_relation, $sum_col);
  132. }
  133. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  134. x = group_it(a, 'name', 'age');
  135. store x into ':OUTPATH:';\,
  136. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  137. b = group a by name;
  138. c = foreach b generate group, SUM(a.age);
  139. store c into ':OUTPATH:';#,
  140. },
  141. {
  142. # single macro definition invoked multiple times
  143. 'num' => 8,
  144. 'pig' => q#define simple_macro(in_relation, min_gpa, max_age) returns c {
  145. b = filter $in_relation by gpa >= $min_gpa and age <= $max_age;
  146. $c = foreach b generate age, name;
  147. }
  148. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  149. x = simple_macro(a, '3.0', '40');
  150. store x into ':OUTPATH:.1';
  151. z = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  152. y = simple_macro(a, '2.0', '50');
  153. store y into ':OUTPATH:.2';#,
  154. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  155. b = filter a by gpa >= 3.0 and age <= 40;
  156. c = foreach b generate age, name;
  157. store c into ':OUTPATH:.1';
  158. d = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  159. e = filter d by gpa >= 2.0 and age <= 50;
  160. f = foreach e generate age, name;
  161. store f into ':OUTPATH:.2';#,
  162. },
  163. {
  164. # macro arg used as function arg
  165. 'num' => 9,
  166. 'pig' => q#define simple_macro(loadfile, sep) returns b {
  167. a = load '$loadfile' using PigStorage('$sep') as (name, age, gpa);
  168. $b = foreach a generate age, name;
  169. }
  170. x = simple_macro(':INPATH:/singlefile/studentcolon10k', ':');
  171. store x into ':OUTPATH:';#,
  172. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studentcolon10k' using PigStorage(':') as (name, age, gpa);
  173. b = foreach a generate age, name;
  174. store b into ':OUTPATH:';#,
  175. },
  176. {
  177. # Multiple returns via split in the data flow
  178. 'num' => 10,
  179. 'pig' => q\define test (in1) returns r1, r2 {
  180. a = load '$in1' using PigStorage() as (name, age, gpa);
  181. $r1 = filter a by (age >= 50 or name > 'fred') and (gpa <= 3.0 or name >= 'bob');
  182. $r2 = filter a by name > 'fred';
  183. }
  184. x1, x2 = test(':INPATH:/singlefile/studenttab10k');
  185. store x1 into ':OUTPATH:.1' using PigStorage;
  186. store x2 into ':OUTPATH:.2' using PigStorage;\,
  187. 'verify_pig_script' => q\a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  188. a1 = filter a by (age >= 50 or name > 'fred') and (gpa <= 3.0 or name >= 'bob');
  189. store a1 into ':OUTPATH:.1' using PigStorage;
  190. a2 = filter a by name > 'fred';
  191. store a2 into ':OUTPATH:.2' using PigStorage;\,
  192. 'floatpostprocess' => 1,
  193. 'delimiter' => ' ',
  194. },
  195. {
  196. # parameter substitution at the top level
  197. 'num' => 11,
  198. 'pig_params' => ['-p', qq(loadfile='singlefile/studenttab10k')],
  199. 'pig' => q#define simple_macro(in_relation, min_gpa, max_age) returns c {
  200. b = filter $in_relation by gpa >= $min_gpa and age <= $max_age;
  201. $c = foreach b generate age, name;
  202. }
  203. a = load ':INPATH:/$loadfile' as (name, age, gpa);
  204. x = simple_macro(a, '3.0', '40');
  205. store x into ':OUTPATH:';#,
  206. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  207. b = filter a by gpa >= 3.0 and age <= 40;
  208. c = foreach b generate age, name;
  209. store c into ':OUTPATH:';#,
  210. }
  211. ]
  212. },
  213. {
  214. 'name' => 'Macro_Scope',
  215. 'tests' => [
  216. {
  217. # re-use of variable in macro and global scope
  218. 'num' => 1,
  219. 'pig' => q#define simple_macro(in_relation, min_gpa, max_age) returns b {
  220. $b = filter $in_relation by $2 >= $min_gpa and $1 <= $max_age;
  221. }
  222. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  223. x = simple_macro(a, '3.0', '40');
  224. b = foreach x generate age, name;
  225. store b into ':OUTPATH:';#,
  226. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  227. b = filter a by gpa >= 3.0 and age <= 40;
  228. c = foreach b generate age, name;
  229. store c into ':OUTPATH:';#,
  230. },
  231. {
  232. #Definition where there is a name collision between parameters in parent/child macro
  233. 'num' => 2,
  234. 'pig' => q\define sum_it(in_relation, relation, sum_col) returns c {
  235. b = foreach $in_relation generate group, SUM($relation.$sum_col);
  236. $c = order b by $1;
  237. }
  238. define group_it(in_relation, group_key, sum_col) returns c {
  239. b = group $in_relation by $group_key ;
  240. $c = sum_it(b, $in_relation, $sum_col);
  241. }
  242. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  243. x = group_it(a, name, age);
  244. store x into ':OUTPATH:';\,
  245. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  246. b = group a by name;
  247. c = foreach b generate group, SUM(a.age);
  248. store c into ':OUTPATH:';#,
  249. },
  250. {
  251. #Definition where there is a name collision between macro and returns value in main pig script
  252. 'num' => 3,
  253. 'pig' => q#define simple_macro(in_relation, min_gpa, max_age) returns c {
  254. b = filter $in_relation by gpa >= $min_gpa and age <= $max_age;
  255. $c = foreach b generate age, name;
  256. }
  257. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  258. c = simple_macro(a, '3.0', '40');
  259. store c into ':OUTPATH:';#,
  260. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  261. b = filter a by gpa >= 3.0 and age <= 40;
  262. c = foreach b generate age, name;
  263. store c into ':OUTPATH:';#,
  264. }
  265. ]
  266. },
  267. {
  268. 'name' => 'Macro_Schema',
  269. 'tests' => [
  270. {
  271. # macro that does not change the schema
  272. 'num' => 1,
  273. 'pig' => q\define test(in) returns a {
  274. $a = filter $in by age > 30;
  275. }
  276. a = load ':INPATH:/singlefile/studenttab10k' as (name:chararray, age:int, gpa:double);
  277. b = test(a);
  278. describe b;\,
  279. 'rc' => 0,
  280. 'expected_out_regex'=> "b: {name: chararray,age: int,gpa: double}"
  281. },
  282. {
  283. # macro that does change the schema
  284. 'num' => 2,
  285. 'pig' => q\define test(in) returns a {
  286. $a = foreach $in generate name;
  287. }
  288. a = load ':INPATH:/singlefile/studenttab10k' as (name:chararray, age:int, gpa:double);
  289. b = test(a);
  290. describe b;\,
  291. 'rc' => 0,
  292. 'expected_out_regex'=> "b: {name: chararray}"
  293. }
  294. ]
  295. },
  296. {
  297. 'name' => 'Macro_Misc',
  298. 'tests' => [
  299. {
  300. #Comments in macro
  301. 'num' => 1,
  302. 'pig' => q#define simple_macro(in_relation, min_gpa, max_age) returns c {
  303. b = filter $in_relation by gpa >= $min_gpa and age <= $max_age;
  304. $c = foreach b generate age, name;
  305. -- add a comment
  306. }
  307. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  308. x = simple_macro(a, '3.0', '40');
  309. store x into ':OUTPATH:';#,
  310. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  311. b = filter a by gpa >= 3.0 and age <= 40;
  312. c = foreach b generate age, name;
  313. store c into ':OUTPATH:';#,
  314. },
  315. {
  316. #register
  317. 'num' => 2,
  318. 'pig' => q\define test (in) returns b {
  319. $b = foreach $in generate name, org.apache.pig.test.udf.evalfunc.Fred() as fred;
  320. }
  321. register :FUNCPATH:/testudf.jar;
  322. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  323. x = test(a);
  324. store x into ':OUTPATH:';\,
  325. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  326. register :FUNCPATH:/testudf.jar;
  327. b = foreach a generate name, org.apache.pig.test.udf.evalfunc.Fred() as fred;
  328. store b into ':OUTPATH:';#,
  329. },
  330. {
  331. #define for streaming combines with define for macros
  332. 'num' => 3,
  333. ,'pig' => q#define CMD `perl -ne 'print $_;'`;
  334. define test(in) returns B {
  335. $B = stream $in through CMD as (name, age, gpa);
  336. }
  337. A = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  338. x = test(A);
  339. store x into ':OUTPATH:';#,
  340. 'verify_pig_script' => q#A = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  341. define CMD `perl -ne 'print $_;'`;
  342. B = stream A through CMD as (name, age, gpa);
  343. store B into ':OUTPATH:';#,
  344. 'floatpostprocess' => 1,
  345. 'delimiter' => ' '
  346. },
  347. {
  348. #JIRA: PIG-2681
  349. 'num' => 4,
  350. ,'pig' => q\
  351. define test (in,out) returns b {
  352. a = load '$in' as (name, age, gpa);
  353. $b = foreach a generate name, org.apache.pig.test.udf.evalfunc.Fred() as fred;
  354. store $b into '$out';
  355. }
  356. register :FUNCPATH:/testudf.jar;
  357. x = test(':INPATH:/singlefile/studenttab10k',':OUTPATH:');
  358. \,
  359. }
  360. ]
  361. },
  362. {
  363. 'name' => 'Macro_Import',
  364. 'tests' => [
  365. {
  366. 'num' => 1,
  367. 'pig' => q#import ':SCRIPTHOMEPATH:/macro1.pig';
  368. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  369. x = simple_macro(a, '3.0', '40');
  370. store x into ':OUTPATH:';#,
  371. 'verify_pig_script' => q#a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  372. b = filter a by gpa >= 3.0 and age <= 40;
  373. c = foreach b generate age, name;
  374. store c into ':OUTPATH:';#,
  375. }
  376. ]
  377. },
  378. {
  379. 'name' => 'Macro_Error',
  380. 'tests' => [
  381. {
  382. # parameter names repeated
  383. 'num' => 1,
  384. 'ignore' => 'https://issues.apache.org/jira/browse/PIG-2247',
  385. 'pig' => q#define simple_macro(in_relation, min_gpa, min_gpa) returns c {
  386. b = filter $in_relation by gpa >= $min_gpa;
  387. $c = foreach b generate age, name;
  388. }
  389. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  390. x = simple_macro(a, '3.0', '40');
  391. store x into ':OUTPATH:';#,
  392. 'expected_err_regex' => "Multiple arguments min_gpa found"
  393. },
  394. {
  395. # undefined parameter in macro
  396. 'num' => 2,
  397. 'pig' => q#define simple_macro(in_relation, min_gpa) returns c {
  398. b = filter $in_relation by gpa >= $min_gpa and age <= $max_age;
  399. $c = foreach b generate age, name;
  400. }
  401. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  402. x = simple_macro(a, '3.0');
  403. store x into ':OUTPATH:';#,
  404. 'expected_err_regex' => "Macro inline failed for macro 'simple_macro'. Reason: Undefined parameter : max_age"
  405. },
  406. {
  407. # name collision between arg and return value
  408. 'num' => 3,
  409. 'pig' => q#define simple_macro(in_relation, min_gpa, c) returns c {
  410. b = filter $in_relation by gpa >= $min_gpa and age <= $c;
  411. $c = foreach b generate age, name;
  412. }
  413. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  414. x = simple_macro(a, '3.0', '40');
  415. store x into ':OUTPATH:';#,
  416. 'expected_err_regex' => "Multiple values found for c"
  417. },
  418. {
  419. # keyword as macro name
  420. 'num' => 4,
  421. 'pig' => q#define foreach(in_relation, min_gpa) returns c {
  422. b = filter $in_relation by gpa >= $min_gpa;
  423. $c = foreach b generate age, name;
  424. }
  425. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  426. x = simple_macro(a, '3.0', '40');
  427. store x into ':OUTPATH:';#,
  428. 'expected_err_regex' => "mismatched input 'foreach' expecting IDENTIFIER"
  429. },
  430. {
  431. # UDF as macro name
  432. 'num' => 5,
  433. 'ignore' => 'https://issues.apache.org/jira/browse/PIG-2248',
  434. 'pig' => q#define COUNT(in_relation, min_gpa) returns c {
  435. b = filter $in_relation by gpa >= $min_gpa;
  436. $c = foreach b generate age, name;
  437. }
  438. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  439. x = COUNT(a, '3.0');
  440. store x into ':OUTPATH:';#,
  441. 'expected_err_regex' => "macro name hides UDF COUNT"
  442. },
  443. {
  444. # redefine a macro
  445. 'num' => 6,
  446. 'pig' => q#define simple_macro(in_relation, min_gpa) returns c {
  447. b = filter $in_relation by gpa >= $min_gpa;
  448. $c = foreach b generate age, name;
  449. }
  450. define simple_macro(in, min_age) returns d {
  451. b = filter $in by age >= $min_age;
  452. $d = foreach b generate age, name;
  453. }
  454. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  455. x = simple_macro(a, '3.0', '40');
  456. store x into ':OUTPATH:';#,
  457. 'expected_err_regex' => "Duplicated macro name 'simple_macro'"
  458. },
  459. {
  460. # invoke non-existent macro
  461. 'num' => 7,
  462. 'pig' => q#
  463. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  464. x = nosuch_macro('a', '3.0', '40');
  465. store x into ':OUTPATH:';#,
  466. 'expected_err_regex' => "Cannot expand macro 'nosuch_macro'. Reason: Macro must be defined before expansion."
  467. },
  468. {
  469. # Specifies two returns, but only actually returns one
  470. 'num' => 8,
  471. 'pig' => q#define simple(in_relation, min_gpa) returns c,d {
  472. b = filter $in_relation by gpa >= $min_gpa;
  473. $c = foreach b generate age, name;
  474. }
  475. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  476. x, y = simple(a, '3.0');
  477. store x into ':OUTPATH:.1';
  478. store y into ':OUTPATH:.2';#,
  479. 'expected_err_regex' => "Invalid macro definition: . Reason: Macro 'simple' missing return alias: d"
  480. },
  481. {
  482. # syntax error in a macro, check for correct line number
  483. 'num' => 9,
  484. 'pig' => q#define simple(in_relation, min_gpa) returns c {
  485. b = fiter $in_relation by gpa >= $min_gpa;
  486. $c = foreach b generate age, name;
  487. }
  488. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  489. x = simple(a, '3.0');
  490. store x into ':OUTPATH:';#,
  491. 'expected_err_regex' => "line 2"
  492. },
  493. {
  494. # too many args passed to macro
  495. 'num' => 10,
  496. 'pig' => q#define simple_macro(in_relation, min_gpa) returns c {
  497. b = filter $in_relation by gpa >= $min_gpa;
  498. $c = foreach b generate age, name;
  499. }
  500. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  501. x = simple_macro(a, '3.0', '40');
  502. store x into ':OUTPATH:';#,
  503. 'expected_err_regex' => "Failed to expand macro 'simple_macro'. Reason: Expected number of parameters: 2 actual number of inputs: 3"
  504. },
  505. {
  506. # return two values, but script only accepts 1
  507. 'num' => 11,
  508. 'pig' => q#define simple(in_relation, min_gpa) returns c,d {
  509. b = filter $in_relation by gpa >= $min_gpa;
  510. $c = foreach b generate age, name;
  511. $d = foreach b generate name, age;
  512. }
  513. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  514. x = simple(a, '3.0');
  515. store x into ':OUTPATH:';#,
  516. 'expected_err_regex' => "Failed to expand macro 'simple'. Reason: Expected number of return aliases: 2 actual number of return values: 1"
  517. },
  518. {
  519. # return 1 value, but script expects 2
  520. 'num' => 12,
  521. 'pig' => q#define simple(in_relation, min_gpa) returns c {
  522. b = filter $in_relation by gpa >= $min_gpa;
  523. $c = foreach b generate age, name;
  524. }
  525. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  526. x, y = simple(a, '3.0');
  527. store x into ':OUTPATH:.1';
  528. store y into ':OUTPATH:.2';#,
  529. 'expected_err_regex' => "Failed to expand macro 'simple'. Reason: Expected number of return aliases: 1 actual number of return values: 2"
  530. }
  531. ]
  532. },
  533. {
  534. 'name' => 'Macro_Import_Error',
  535. 'tests' => [
  536. {
  537. # import non-existent file
  538. 'num' => 1,
  539. 'ignore' => 1, # different error message for different version of hadoop
  540. 'pig' => q#import 'nosuchfile';
  541. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  542. x = simple_macro('a', '3.0', '40');
  543. store x into ':OUTPATH:';#,
  544. 'expected_err_regex' => "Failed to import file 'nosuchfile'. Reason: Can't find the Specified file nosuchfile"
  545. },
  546. {
  547. # import a macro with a syntax error
  548. 'num' => 2,
  549. 'pig' => q#import ':SCRIPTHOMEPATH:/macro_bad1.pig';
  550. a = load ':INPATH:/singlefile/studenttab10k' as (name, age, gpa);
  551. x = simple_macro(a, '3.0', '40');
  552. store x into ':OUTPATH:';#,
  553. 'expected_err_regex' => "Invalid macro definition"
  554. }
  555. ]
  556. }
  557. ],
  558. },
  559. ;
  560. # import non-existent file, import script with error