PrG_Workwith_Blobs.xml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="Working_with_BLOBs">
  5. <title><emphasis role="bold">Working with BLOBs</emphasis></title>
  6. <para>BLOB (Binary Large OBject) support in ECL begins with the DATA value
  7. type. This type may contain any type of data, making it perfect for housing
  8. BLOB data.</para>
  9. <para>There are essentially three issues around working with BLOB
  10. data:</para>
  11. <para>1) How to get the data into the HPCC (spraying).</para>
  12. <para>2) How to work with the data, once it is in the HPCC.</para>
  13. <para>3) How to get the data back out of the HPCC (despraying).</para>
  14. <sect2 id="Spraying_BLOB_Data">
  15. <title>Spraying BLOB Data</title>
  16. <para>In the HPCCClientTools.PDF there is a chapter devoted to the
  17. DFUplus.exe program. This is a command line tool with specific options
  18. that allow you to spray and despray files into BLOBs in the HPCC. In all
  19. the examples below, we'll assume you have a DFUPLUS.INI file containing
  20. the standard content described in that section of the PDF.</para>
  21. <para>The key to making a spray operation write to BLOBs is the use of the
  22. <emphasis>prefix=Filename,Filesize</emphasis> option. For example, the
  23. following command line sprays all the .JPG and .BMP files from the
  24. c:\import directory of the 10.150.51.26 machine into a single logical file
  25. named LE::imagedb:</para>
  26. <programlisting>C:\&gt;dfuplus action=spray srcip=10.150.51.26 srcfile=c:\import\*.jpg,c:\import\*.bmp
  27. dstcluster=le_thor dstname=LE::imagedb overwrite=1
  28. PREFIX=FILENAME,FILESIZE nosplit=1</programlisting>
  29. </sect2>
  30. <sect2 id="Working_with_BLOB_Data">
  31. <title>Working with BLOB Data</title>
  32. <para>Once you've sprayed the data into the HPCC you must define the
  33. RECORD structure and DATASET. The following RECORD structure defines the
  34. result of the spray above:</para>
  35. <programlisting>imageRecord := RECORD
  36. STRING filename;
  37. DATA image;
  38. //first 4 bytes contain the length of the image data
  39. UNSIGNED8 RecPos{virtual(fileposition)};
  40. END;
  41. imageData := DATASET('LE::imagedb',imageRecord,FLAT);
  42. </programlisting>
  43. <para>The key to this structure is the use of variable-length STRING and
  44. DATA value types. The filename field receives the complete name of the
  45. original .JPG or .BMP file that is now contained within the image field.
  46. The first four bytes of the image field contain an integer value
  47. specifying the number of bytes in the original file that are now in the
  48. image field.</para>
  49. <para>The DATA value type is used here for the BLOB field because the JPG
  50. and BMP formats are essentially binary data. However, if the BLOB were to
  51. contain XML data from multiple files, then it could be defined as a STRING
  52. value type. In that case, the first four bytes of the field would still
  53. contain an integer value specifying the number of bytes in the original
  54. file, followed by the XML data from the file.</para>
  55. <para>The addition of the RecPos field (a standard ECL “record pointer”
  56. field) allows us to create an INDEX, like this:</para>
  57. <programlisting>imageKey := INDEX(imageData,{filename,fpos},'LE::imageKey');
  58. BUILDINDEX(imageKey);</programlisting>
  59. <para>Having an INDEX allows you to work with the imageData file in keyed
  60. JOIN or FETCH operations. Of course, you can also perform any operation on
  61. the BLOB data files that you would do with any other file in ECL.</para>
  62. </sect2>
  63. <sect2 id="Despraying_BLOB_Data">
  64. <title>Despraying BLOB Data</title>
  65. <para>The DFUplus.exe program also allows you to despray BLOB files from
  66. the HPCC, splitting them back into the separate files they originated
  67. from. The key to making a despray operation write BLOBs to separate files
  68. is the use of the <emphasis>splitprefix=Filename,Filesize</emphasis>
  69. option. For example, the following command line desprays all the BLOB data
  70. to the c:\import\despray directory of the 10.150.51.26 machine from the
  71. single logical file named LE::imagedb:</para>
  72. <programlisting>C:\&gt;dfuplus action=despray dstip=10.150.51.26 dstfile=c:\import\despray\*.*
  73. srcname=LE::imagedb PREFIX=FILENAME,FILESIZE nosplit=1</programlisting>
  74. <para>Once this command has executed, you should have the same set of
  75. files that were originally sprayed, recreated in a separate
  76. directory.</para>
  77. </sect2>
  78. </sect1>