Abis.be

547 views
467 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
547
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Abis.be

  1. 1. •• •• •• •• DDUG 20 November 2002 •• •• •• ••• •••• ••••••••• DB2 UDB Extenders: XML & Text Extender Pieter Bedert ABIS Training & Consulting Postbus 122, NL-3440 AC Woerden, tel: +31-348-435570 Postbus 220, BE-3000 Leuven, tel: +32-16-245610 http://www.abis.be - e-mail: training@abis.be ABIS Training & Consulting 1
  2. 2. Agenda DB2 UDB Extenders: XML & Text Extender Introducing Extenders Text Extender • Features • DB2 UDB Implementation • Enabling the Text Extender / Demo XML Extender • Introducing XML • Features • DB2 UDB Implementation • Enabling the XML Extender / Demo Text Extender for XML documents • Enabling / Demo DDUG 20 November 2002 2
  3. 3. Introducing Extenders DB2 UDB Extenders: XML & Text Extender What is a DB2 Extender? An Extender offers you • Stored Procedures • Triggers • User Defined Functions (UDF) • User Defined Datatypes (UDT) • Supporting Tables to Extend the DB2 functionality! DDUG 20 November 2002 3
  4. 4. Text Extender: Features DB2 UDB Extenders: XML & Text Extender Search for course in “HTML”? <HTML> <title>XML base course</title> This 4 day course will introduce you in a new IT domain ... </HTML> Course Table <HTML><title>XML base course</ <HTML> 1 XML title>This 4 day course will introduce you in a new IT domain ... </HTML> <title>HTML base course</title> <HTML><title>HTML base course</ title>It is impossible to imagine an It is impossible to imagine an 2 HTML internet without HTML, this base course will give you... </HTML> internet without HTML, this base <HTML><title>DB2 UDB for NT/ course will give you... 3 DB2 UNIX</title>DB2 is THE relational database ... </HTML> </HTML> <HTML> <title>DB2 UDB for NT</title> DB2 is THE relational database ... </HTML> DDUG 20 November 2002 4
  5. 5. Text Extender: Features DB2 UDB Extenders: XML & Text Extender When enabling Text for search by DB2, DB2 will: • Ignore “stop words” - the, and, or,... - list can be modified by the DBA / application developer • Ignore tags - XML-tags, HTML-tags,... - kind of text must be indicated by DBA / application developer DDUG 20 November 2002 5
  6. 6. Text Extender: Features DB2 UDB Extenders: XML & Text Extender When enabling Text for search by DB2, DB2 users will be able to: • Search documents using SQL with UDF’s SELECT course_id FROM course_table WHERE db2tx.contains(coursedesc_texth, ‘”HTML”’) = 1 SELECT course_id, db2tx.no_of_matches(coursedesc_texth, ‘”HTML”’) as #occurences FROM course_table WHERE db2tx.contains(coursedesc_texth, ‘”HTML”’) = 1 ORDER BY 2 DESC DDUG 20 November 2002 6
  7. 7. Text Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender When you enable - a Column (varchar / CLOB) - an External File for Text Search in a DB2 table, DB2 will: - Build an INDEX - Add a HANDLE-COLUMN. DDUG 20 November 2002 7
  8. 8. Text Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender Index Options = Search Options • PRECISE Index · “exact word” index · “stop words” ignored • LINGUISTIC Index · “stemmed word” index · “stop words” ignored · dictionary needed! (Dutch is available) • DUAL Index · PRECISE index + LINGUISTIC index • NGRAM Index · all words entered “as is” · character based search · fuzzy search support DDUG 20 November 2002 8
  9. 9. Text Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender Consider: After - INSERT - UPDATE - DELETE NO AUTOMATIC INDEX SYNCHRONIZATION! The DBA / Application Developer has to - manually update the index - schedule the automatic index updates DDUG 20 November 2002 9
  10. 10. Text Extender: Enabling the Text Extender / Demo DB2 UDB Extenders: XML & Text Extender Creating and Starting a Text Extender service (NT) / deamon (UNIX) Create Text Extender Instance: > txicrt z/OS and OS/390: Use the DESCUST Utility in the USS Drop Text Extender Instance: > txidrop Start Text Extender Instance: > txstart Stop Text Extender Instance: > txstop DDUG 20 November 2002 10
  11. 11. Text Extender: Enabling the Text Extender / Demo DB2 UDB Extenders: XML & Text Extender Using the Text Extender Administration Interface, > db2tx ... Prepare (enable) your database for Text Extender use. > db2tx enable database z/OS and OS/390 >> db2tx ENABLE SERVER FOR DB2TEXT Configure the Default Index values. > db2tx change text cfg using ... > db2tx get text configuration Prepare (enable) your table / column for Text Extender use. > db2tx enable text column “table_name” “column_name” handle “handle_column” Maintain (update/check status) the index > db2tx update index “table_name” handle “handle_column” > db2tx get index status “table_name” handle “handle_column” DDUG 20 November 2002 11
  12. 12. Text Extender: Enabling the Text Extender / Demo DB2 UDB Extenders: XML & Text Extender From now on SQL will do the job: > db2 insert into ... > db2 update ... > db2 delete ... Don’t forget to update the index! > db2tx update index ... DDUG 20 November 2002 12
  13. 13. Text Extender: Enabling the Text Extender / Demo DB2 UDB Extenders: XML & Text Extender Searching the text: SELECT ... FROM ... WHERE ... Using the Text Extender UDF’s: SELECT course_id FROM course_table WHERE db2tx.contains(coursedesc_texth, ‘”HTML”’) = 1 SELECT course_id, db2tx.no_of_matches(coursedesc_texth, ‘”HTML”’) as #occurences FROM course_table WHERE db2tx.contains(coursedesc_texth, ‘”HTML”’) = 1 ORDER BY 2 DESC DDUG 20 November 2002 13
  14. 14. XML Extender: Introducing XML DB2 UDB Extenders: XML & Text Extender What is an XML-document? • Adds metadata to your data • Hierarchical structure • Consists of Elements and Attributes <Course id=”1”> <Title>DB2 UDB for OS/390<Title> <Description>This Course reveals the secrets of the leading RDBMS ... </Description> <Prereq_list> <Prereq>Know the concepts of a relational DataBase</Prereq> <Prereq>Know some basic SQL</Prereq> <Prereq>Have some experience on an OS/390 platform</Prereq> </Prereq_list> </Course> DDUG 20 November 2002 14
  15. 15. XML Extender: Introducing XML DB2 UDB Extenders: XML & Text Extender Structure of an XML document is defined: Schema / DTD Document Type Definition (DTD) <!ELEMENT Course (Title,Description,Prereq_list)> <!ATTLIST Course id CDATA #REQUIRED> <!ELEMENT Title (#PCDATA)> <!ELEMENT Description (#PCDATA)> <!ELEMENT Prereq_list (Prereq+)> <!ELEMENT Prereq (#PCDATA)> <Course id=”1”> <Title>DB2 UDB for OS/390<Title> <Description>This 4 day course will introduce you in a new IT domain ... </Description> <Prereq_list> <Prereq>Know the concepts of a relational DataBase</Prereq> <Prereq>Know some basic SQL</Prereq> <Prereq>Have some experience on an OS/390 platform</Prereq> </Prereq_list> </Course> DDUG 20 November 2002 15
  16. 16. XML Extender: Features DB2 UDB Extenders: XML & Text Extender A table: db2xml.DTD_REF is supplied: • To store your DTD documents • To VALIDATE inserted documents DDUG 20 November 2002 16
  17. 17. XML Extender: Features DB2 UDB Extenders: XML & Text Extender Store an entire XML document: - XMLVarchar - XMLCLOB - XMLFILE (external file) and extract some data for rapid search. (XColumn) Decompose an XML-document (XCollection) - Extract data from XML-document - Distribute the data in existing DB2 tables Compose an XML-document from DB2 data (XCollection) DDUG 20 November 2002 17
  18. 18. XML Extender: Features DB2 UDB Extenders: XML & Text Extender XColumn • Store an entire XML document • Validate the XML document before insert • Copy elements and attributes to side tables - For fast searching - Can be indexed When to use XColumn? · (almost) read only XML documents · Archiving or Auditing purposes · The XML document has to stay intact! DDUG 20 November 2002 18
  19. 19. XML Extender: Features DB2 UDB Extenders: XML & Text Extender Side / Search XML Tables Side Table 1 Insert T R XML Table I Side Table 2 G G E R S Side Table 3 DDUG 20 November 2002 19
  20. 20. XML Extender: Features DB2 UDB Extenders: XML & Text Extender XCollection • Validate XML document before decomposing • Decompose XML documents and distribute XML data to existing DB2 tables (= NO XML IN TABLES) • Compose XML documents using DB2 data and SQL When to use XCollection? · Your XML documents are used to transfer data, you don’t want to modify database definitions. · Your XML data is updated frequently. · You want to use SQL to compose your XML documents. DDUG 20 November 2002 20
  21. 21. XML Extender: Features DB2 UDB Extenders: XML & Text Extender XML Decompose DB2 Table Table Table 1 2 3 Compose XML DDUG 20 November 2002 21
  22. 22. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender Document Access Definition (DAD) • XML document. • Indicates if DB2 needs to validate. • Indicates the method (XColumn / XCollection). • Maps XML to Relational data. <DAD> <dtdid>g:DDUGDDUGXColumnXMLdocsCourseDesc.dtd</dtdid> <validation>YES</validation> <XColumn/> </DAD> DDUG 20 November 2002 22
  23. 23. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender XColumn: A Column Contains an entire XML document • Needs an XML UDT · XMLvarchar · XMLCLOB · XMLFILE • Needs a DAD with: · Validation: NO / YES (dtdid) · Side table definitions · Mapping between side table columns and XML data (Location Path) After enabling XColumn, DB2 will: - Create all Side Tables + Default view - Create triggers - Add referential columns DDUG 20 November 2002 23
  24. 24. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender Example: XColumn DAD <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE DAD SYSTEM "f:dxxdtddad.dtd"> <DAD> <dtdid>g:DDUGDDUGXColumnXMLdocsCourseDesc.dtd</dtdid> <validation>YES</validation> <Xcolumn> <table name="Side_Course_table"> <column name="course_id" type="integer" path="/Course/@id" multi_occurrence="NO"/> <column name="course_title" type="character(20)" path="/Course/Title" multi_occurrence="NO"/> </table> <table name="Side_Prereq_table"> <column name="course_prereq" type="varchar(60)" path="/Course/Prereq_list/Prereq" multi_occurrence="YES"/> </table> </Xcolumn> </DAD> DDUG 20 November 2002 24
  25. 25. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender XCollection: No XML in your Database, only XML data inserted • Enable Collection with a DAD (optional) • No preparation needed at Table / Column level • A DAD / Collection has to be mentioned at each - Insert operation: dxxShredXML() / dxxInsertXML() · Validation: NO / YES (dtdid) · Mapping between XML and RDB (RDB.DAD) - Retrieve operation: dxxGenXML() / dxxRetrieveXML() · Mapping between RDB and XML (RDB or SQL mapping) DDUG 20 November 2002 25
  26. 26. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender Example: XCollection RDB_node mapping DAD RDB_node Condition used for FK/PK relationships <element_node name="Seminar"> <RDB_node> <table name="seminars"/> <table name="speakers"/> <condition>speakers.seminar_id=seminars.id</condition> </RDB_node> DDUG 20 November 2002 26
  27. 27. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender Element and Attribute Values Inserted in Columns <attribute_node name="id"> <RDB_node> <table name="seminars"/> <column name="id" type="integer"/> </RDB_node> </attribute_node> <element_node name="Person" multi_occurrence="YES"> <element_node name="LastName"> <text_node> <RDB_node> <table name="persons"/> <column name="lastname" type="character(20)"/> </RDB_node> </text_node> </element_node> DDUG 20 November 2002 27
  28. 28. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender XCollection: SQL mapping <Xcollection> <SQL_stmt>select seminars.id as se_id, name, city, speakers.id as sp_id, firstname, lastname from speakers, seminars where seminars.id = seminar_id and company_name = 'ABIS' order by se_id, sp_id </SQL_stmt> DDUG 20 November 2002 28
  29. 29. XML Extender: DB2 UDB Implementation DB2 UDB Extenders: XML & Text Extender Contents of Elements & Attributes is derived from Selected Columns <element_node name="Seminar"> <element_node name="Name"> <text_node> <column name="name" type="character(20)"/> </text_node> </element_node> <element_node name="Person" multi_occurrence="YES"> <element_node name="FirstName"> <text_node> <column name="firstname" type="character(20)"/> </text_node> </element_node> DDUG 20 November 2002 29
  30. 30. XML Extender: Enabling the XML Extender / Demo DB2 UDB Extenders: XML & Text Extender Using the XML Extender Administration Interface, > dxxadm ... Prepare (enable) your database for XML Extender use. > dxxadm enable_db “db-name” z/OS OS/390 >> dxxadm enable_server -a “ssid” ... Insert a DTD in the DTD_REF table for validation. DDUG 20 November 2002 30
  31. 31. XML Extender: Enabling the XML Extender / Demo DB2 UDB Extenders: XML & Text Extender XColumn Enable an XML Column with a DAD > dxxadm enable_column “database-name” “table-name” “column-name” “dad-location” Use regular SQL to insert XML documents DDUG 20 November 2002 31
  32. 32. XML Extender: Enabling the XML Extender / Demo DB2 UDB Extenders: XML & Text Extender XCollection Use the stored procedures and a DAD to decompose / compose your XML OR Use the sample Programs: • Decompose > shred “database-name” “dad-location” “xml-location” • Compose > tests2x “database-name” “dad-location” “xml-result-table” DDUG 20 November 2002 32
  33. 33. Text Extender For XML documents: Enabling and Demo DB2 UDB Extenders: XML & Text Extender Enable the Text Extender Modify the desmodels.ini (Use the XML Location Path) ; list of document models [MODELS] modelname = Course [Course] Course = /Course Content = /Course/Content HLContent = /Course/Content/HLContent Enable Column “Sections-enabled” and mention the model Use the UDF’s to Query: > db2 select db2tx.no_of_matches(hfile, 'model Course sections (HLContent) "storage"') from xmlfile DDUG 20 November 2002 33
  34. 34. More Information about DB2 Extenders? DB2 UDB Extenders: XML & Text Extender Pieter Bedert, ABIS Training and Consulting e-mail: pbedert@abis.be ABIS Nieuwsbrief: Exploring DB2 http://www.abis.be/nexploredb2/nexploredb2.html ABIS UP-TO-DATE seminar Integrating IBM technologies: Web Services (Woerden 12-13/12/2003) http://www.abis.be/ncourses/N_UTDTOC.html DDUG 20 November 2002 34

×