setup_fetch.ecl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. import Std.File AS FileServices;
  14. FetchData := DATASET([
  15. {3000, 'FL', 'Boca Raton', 'London', 'Bridge'},
  16. {3500, 'FL', 'Boca Raton', 'Anderson', 'Sue'},
  17. {3500, 'FL', 'Boca Raton', 'Anderson', 'John'},
  18. {35, 'FL', 'Boca Raton', 'Smith', 'Frank'},
  19. {3500, 'FL', 'Boca Raton', 'Johnson', 'Joe'},
  20. {50, 'FL', 'Boca Raton', 'Smith', 'Sue'},
  21. {135, 'FL', 'Boca Raton', 'Smith', 'Nancy'},
  22. {3500, 'FL', 'Boca Raton', 'Johnson', 'Sue'},
  23. {235, 'FL', 'Boca Raton', 'Smith', 'Fred'},
  24. {335, 'FL', 'Boca Raton', 'Taylor', 'Frank'},
  25. {3500, 'FL', 'Boca Raton', 'Johnson', 'Jane'},
  26. {3500, 'FL', 'Boca Raton', 'Jones', 'Frank'},
  27. {3500, 'FL', 'Boca Raton', 'Jones', 'Tommy'},
  28. {3500, 'FL', 'Boca Raton', 'Doe', 'John'},
  29. {3500, 'FL', 'Boca Raton', 'Anderson', 'Joe'},
  30. {3500, 'FL', 'Boca Raton', 'Doe', 'Jane'},
  31. {3500, 'FL', 'Boca Raton', 'Doe', 'Joe'},
  32. {3500, 'FL', 'Boca Raton', 'Johnson', 'Larry'},
  33. {3500, 'FL', 'Boca Raton', 'Johnson', 'John'},
  34. {3500, 'FL', 'Boca Raton', 'Anderson', 'Larry'},
  35. {3500, 'FL', 'Boca Raton', 'Anderson', 'Jane'},
  36. {30, 'FL', 'Boca Raton', 'Smith', 'Zeek'}], DG_FetchRecord);
  37. // Try to make sure that there are at least 2 parts with data on... This gets a little hairy in places!
  38. // Note that in order to facilitate testing of preload / preloadIndexed versions of data, we generate the same file under 3 names
  39. #IF (useLocal=true)
  40. twoways := distribute(FetchData, IF(lname < 'Jom', 1, 0));
  41. output(sort(twoways,record,local),,DG_FetchFileName,OVERWRITE);
  42. output(sort(twoways,record,local),,DG_FetchFilePreloadName,OVERWRITE);
  43. output(sort(twoways,record,local),,DG_FetchFilePreloadIndexedName,OVERWRITE);
  44. BUILDINDEX(DG_FetchIndex1,DG_FetchIndex1Name,OVERWRITE,NOROOT);
  45. BUILDINDEX(DG_FetchIndex2,DG_FetchIndex2Name,OVERWRITE,NOROOT);
  46. #ELSE
  47. twoways := distribute(FetchData, IF(lname < 'Jom', 0, 1));
  48. output(sort(twoways,record,local),,DG_FetchFileName,OVERWRITE);
  49. output(sort(twoways,record,local),,DG_FetchFilePreloadName,OVERWRITE);
  50. output(sort(twoways,record,local),,DG_FetchFilePreloadIndexedName,OVERWRITE);
  51. #IF (usePayload=false)
  52. sortedFile := SORT(DG_FETCHFILE, Lname,Fname,__filepos, LOCAL);
  53. BUILDINDEX(sortedFile,{Lname,Fname,STRING100 tfn := TRIM(Fname), state, STRING100 blobfield := fname+lname, __filepos},DG_FetchIndex1Name, OVERWRITE, SORTED);
  54. BUILDINDEX(sortedFile,{Lname,Fname,STRING100 tfn := TRIM(Fname), state, STRING100 blobfield := fname+lname, __filepos}, DG_FetchIndex2Name, OVERWRITE, SORTED);
  55. #ELSE
  56. #IF (useVarIndex=true)
  57. sortedFile := SORT(DG_FETCHFILE, Lname,Fname,state ,__filepos, LOCAL);
  58. BUILDINDEX(sortedFile,{Lname,Fname},{STRING tfn := TRIM(Fname), state, STRING blobfield {blob}:= fname+lname, __filepos},DG_FetchIndex1Name, OVERWRITE, SORTED);
  59. BUILDINDEX(sortedFile,{Lname,Fname},{STRING tfn := TRIM(Fname), state, STRING blobfield {blob}:= fname+lname, __filepos},DG_FetchIndex2Name, OVERWRITE, SORTED);
  60. #ELSE
  61. sortedFile := SORT(DG_FETCHFILE, Lname,Fname,state ,__filepos, LOCAL);
  62. BUILDINDEX(sortedFile,{Lname,Fname},{STRING100 tfn := TRIM(Fname), state, STRING100 blobfield := fname+lname, __filepos}, DG_FetchIndex1Name, OVERWRITE, SORTED);
  63. BUILDINDEX(sortedFile,{Lname,Fname},{STRING100 tfn := TRIM(Fname), state, STRING100 blobfield := fname+lname, __filepos}, DG_FetchIndex2Name, OVERWRITE, SORTED);
  64. #END
  65. #END
  66. #END
  67. fileServices.AddFileRelationship( DG_FetchFileName, DG_FetchFilePreloadName, '', '', 'view', '1:1', false);
  68. fileServices.AddFileRelationship( DG_FetchFileName, DG_FetchFilePreloadIndexedName, '', '', 'view', '1:1', false);
  69. fileServices.AddFileRelationship( DG_FetchFileName, DG_FetchIndex1Name, '', '', 'view', '1:1', false);
  70. fileServices.AddFileRelationship( DG_FetchFileName, DG_FetchIndex1Name, '__fileposition__', '__filepos', 'link', '1:1', true);
  71. fileServices.AddFileRelationship( DG_FetchFileName, DG_FetchIndex2Name, '', '', 'view', '1:1', false);
  72. fileServices.AddFileRelationship( DG_FetchFileName, DG_FetchIndex2Name, '__fileposition__', '__filepos', 'link', '1:1', true);