SlideShare a Scribd company logo
1 of 26
Download to read offline
斉藤 太郎 (Taro L. Saito)
                      東京大学

            2008年12月20日
ACM SIGMOD 日本支部第40回大会




  http://www.xerial.org/
さあ みんなで SAX, DOM,
XMLのプロジェクト                  XPATH, XQUERY, DTD, XML
             我が社にとってXMLは重
を始めることにした                      SCHEMA, RELAX NG
             要だ。今までのテーブル
                                 を勉強するんだ!
             と違って、まったく新し
              いデータ構造だからな




    はっきり言って、たいへんです。
     › XMLを使うのにこんなに学ぶことがあるなんて

                                              2
   XMLのいいところ
    › テキスト(簡単に扱える)
    › XMLの方が直観的なデータ構造に近い
                                              <Company value=“1”>
                                               <Emp value=“e1”>
                                                 <Office>NY</Office>
                                               </Emp>
                                               <Emp value=“e2”>
                                        Co       <Office>NY</Office>
                                               </Emp>
Company Employee Office                       </Company>

    1         e1          NY
                               Emp           Emp
    1         e2          NY
                                     e1            e2

        Relational Data        Office     Office
        (テーブルデータ)                    NY            NY
                                   XML Data                  3
   XMLに変換されたテーブルデータを取り出したい
   例題:テーブルの一行 (Co, Emp, Office) をXML
    から取り出す
    › 例えば、XPath(経路を指定して検索する方法)では
        /Co/Emp/Office と書く

                                      Co
    Co      Emp   Office
    1       e1     NY
    1       e2     NY        Emp           Emp
                                   e1            e2

         Relational Data     Office     Office
                                   NY            NY
                               XML Data
                                                      4
    テーブルからXMLへの変換の仕方は、一通
     りではない      Co

Co    Emp   Office
1     e1     NY                  Emp        Emp
1     e2     NY                        e1         e2

Relational Data
                      Co     Office         Office
                                       NY         NY
                                                          Office
                                                                  NY
                  Office
                            NY

                                                     Co   Emp          Emp
              Emp          Emp
                                                             e1          e2
                     e1          e2
                                                                         5
   XML構造全体を把握していないと、構造のゆら
    ぎのため、正しい経路を指定できない
    › データベース設計者と利用者の意思疎通が必要
      不可欠
       Co                       Co
                                                     Office
                                                             NY
                       Emp           Emp
    Office
             NY              e1            e2
                                                Co   Emp          Emp
 Emp        Emp        Office     Office                e1          e2
    e1            e2         NY            NY
                                                 /Office[Co]/Emp
/Co/Office/Emp         /Co/Emp[Office]
                                      [X] : 枝分かれ
                                                                   6
 鍵となる考え方
                                › Relation(行データ)は、XML
Co    Emp    Office              に埋め込まれているだけ
1     e1         NY
1     e2         NY
Relational Data                          Co

             Co
                                 Emp          Emp             Office
                                                                      NY
                                       e1           e2
            Office
                      NY        Office      Office       Co   Emp          Emp
                                       NY           NY
                                                                 e1          e2
       Emp        Emp
            e1             e2                                               7
XPathは要らないんじゃない?




                   8
   XMLからrelation(テーブル)を取り出す手法
        › 検索にはSQL文を使う
       SELECT Co, Emp, Office from (XML Data)
                          Co                    Co
                                                                        Office

                 Emp           Emp             Office
                                                                                 SQL over
                                                                                 NY


Input XML Data         e1            e2                  NY
                                                                                  XML!
                                                                   Co   Emp           Emp
                 Office        Office     Emp        Emp                   e1           e2
                       NY            NY        e1             e2

                                          Co        Emp       Office
                                          1         e1         NY
                  Result
                                          1         e2         NY

       設計者がどんなXML構造を使っていて
        も、SQL文は影響を受けない                                                                       9
   SQL文 SELECT A, B, C をXMLの構造を検索する問い
    合わせに変換する
    › (A, B, C)のXML表現では、様々な構造のゆらぎが生じ得る

                A               B
        B               A               C
                B               C               …..
    A       C       B       C       A       B
                C               A

   一般に、N個のノードには NN-1 種類の構造のゆ
    らぎがある
                                                 10
   (A, B, C) が amoeba (アメーバ)構造
     A, B, Cのうち、どれか一つが他の親ノー
    ド(祖先も含む)になっている

            A               B
    B               A               C
            B               C               …..
A       C       B       C       A       B
            C               A

   Amoeba joinは、すべてのamoeba構造を
    XMLから取り出す操作.
                                             11
   Amoebaではあるが、relation(行データ)にはな
    らない構造がある
    › なぜ、下図のamoebaがrelationにならないのか?
   それは、XMLの構造の中に、functional
    dependencies (FD) が暗黙に想定されているから
                                      1
                            company
          Company
                                            M

                                          office
      Office   Office                        1
                                 N
                              employee
    Emp   Emp Emp Emp
                        ER-diagram (Data Model)
                                                   12
   FD: X -> Y (ノードXからユニークな(たった1つの)ノードY
    が見つけられる)
    › employee-> office (各employee は特定のofficeに所属している)
    › office -> company (各office は、ある会社に属している)
   Relation in XML では、個々のFDが、それぞれamoeba構造
    をとる必要がある
                                            1
                                  company
          Company
                                                  M

                        amoebaに
                                                office
       Office   Office なっていない!                     1
                                      N
                                   employee
    Emp    Emp Emp Emp
                            ER-diagram (Data Model)
                                                         13
 company に、M 個所のoffice、またそれぞれのoffice
    にN人のemployeeがいるとすると…
   (company, office, employee) の組み合わせの数:
     › M = 100, N = 5 のとき 100 x (100 x 5) = 50,000
   一方、正しい組み合わせの数は M * N = 500

                                                          1
                                                company
                Company
                                                                M

                                                              office
      Office        Office           Office                      1
                                                    N

Emp   Emp Emp Emp
                                                 employee
                     Emp Emp   Emp    Emp Emp

                                                                14
    FD: Emp -> Office, Office -> Company
      ボトムアップにamoebaを組み立てていく
       1.      Amoeba Join (Employee, Office)
       2.      Amoeba Join (Office, Company)


                                                              1
                                                    company
                      Company
                                                                    M

                                                                  office
      Office            Office           Office                      1
                                                        N

Emp   Emp Emp Emp
                                                     employee
                         Emp Emp   Emp    Emp Emp

     FDを考慮すると、関係のない構造をはじくことができる                                         15
   FDを考慮したamoeba join
    › データサイズに比例した性能




                         16
   SQLからXMLクエリへ自動変換
    › SELECT Co, Office, Emp
       FD: Emp -> Office, Office -> Co

                 Co                     Office
     Office                  Co                       Emp
               Office                   Emp
                                                                 …..
    Co   Emp            Office    Emp            Co     Office
                Emp                      Co


   XMLクエリは、Relation(テーブル構造)とFD
    から自動的に定まる

                                                                 17
   1対多 (one-to-many) と1対1 (one-to-one)
    › 例:FD、 Emp -> Office は、以下のような関係に対応:
       個々のemployeeは、あるofficeに属している
       逆に考えて、officeには、複数の employeeがいる (1対多)
   1対1、1対多の関係(FD)を見つけるには、
    › XMLデータ中から親子関係にある組の出現頻度を数える
    › あるいは、ERダイアグラム・UML(データモデル)から直接抽出

       Company                 company
                                         1

                                               M

             Office                          office
    Office
                                                1
                                   N

Emp     Emp Emp Emp              employee
                                                      18
   「XMLは木構造」という発想から抜け出す
     › XML := Relation + Annotation
   ステップ
     › 1. XMLデータからRelation(行データ)を見つける
     › 2. 1対多のFDを見つける
     › 3. SQLで問い合わせ文を書く company
        SELECT Co, Emp, Office                c1
                                                    annotation

                                  employee    absent
   備考:                e1
     アノテーションをクエリに含め
      ることもできる                                employee
                         office
                                NY                      e2
     一部はXMLのまま、その他は
      relationという構成も可能
                                              office
                                                       NY 19
 Relation   in XML
  › AmoebaとFDで、構造が決まる

 Relational-Style    XML Query
  › SQLを用いて、XMLからrelationを取り出せる
  › 構造のゆらぎに強い
     XMLデータの組み方に自由度が生まれる

 Good-bye XPath!!
  › 目的のXML構造は、パスで指定せずとも、テー
    ブルスキーマとFDから自動的に決まる
                                  20
   技術的な詳細は論文の方に
    › Relational-Style XML Query. Taro L. Saito,
      Shinichi Morishita. SIGMOD 2008.
   RDBMSと同じ枠組みで実装できる
    › 問い合わせ代数・クエリの最適化など
 データベースの統合にも活用できる
 XMLデータのスキーマ変更が容易に
    › RDBMSのスキーマ拡張とほぼ同じ
 Relationalデータに、XMLを使った
  annotationを付加しやすくなる
 …などなど
                                                   21
   実は「SQLでいける」
       よくよく見ると、XMLの中にテーブル構造(relational
        data)が埋め込まれている場合がほとんど

XMLのプロジェクト          我が社にとってXMLは      Relational Styleで
を始めることにした
                    重要だ。でも、XMLと      考えれば怖くない!!
                     いってもほとんど
                    テーブルデータなんだ




 XML技術の深みにはまる前に…
          Think in Relational Style!!!
                                                 22
23
   OR (Object-Relational) マッピング
    › Object-XMLマッピングのサブセット
    › プログラム言語のクラス定義から、スキーマ定義を抽出
       Javaなどのリフレクション機能を用いると全自動
    › オブジェクトデータをXMLや、RDBに出力
       AmoebaとFDさえ満たしていれば、どのようなXML構造
        で出力してもOK
    › XML・RDBデータを読み込んで、オブジェクトを生成
       SAX, DOMでのプログラミングが一切不要になる
   他の木構造データにも使える
    › JSON, YAMLなども扱える
    › CSVなどテーブル形式のデータでも構わない

                                   24
   Class定義からrelation & FDを抽出
     › Relation: (id, start, end , name)
     › FD: gene -> id, start, end, name
     › XML からList<Gene>を取りだす
                                                  Class Definition (Java)
                            class Gene {
<data>                        private int id;
 <gene id=“1”>                private int start;
  <start>100</start>          private int end;
                              private String name;
  <end>3000</end>
  <name>A</name>                public Gene(){}
 </gene>
 <gene id=“2”>                  public void setId(int id)
                                { this.id = id; }
  <start>3500</start>           public void setName(String name)
  <end>7000</end>               { this.name = name; }
 </gene>                         // followed by other setters
</data>                         ….
                            }                                      25
 Xerial   (エクセリアル)   Project
  › XML DBMSの実装、OR・OXマッピング関連
    のライブラリなど
  › http://www.xerial.org/
 Relational-Style    XML Query
  › 開発版をオープンソースで公開予定
     Apache License Version 2.0
  › Javaによる実装
     MavenのCentral Repository経由で配布さ
      れます

                                   26

More Related Content

More from Taro L. Saito

Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Taro L. Saito
 
Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020
Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020
Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020Taro L. Saito
 
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020Taro L. Saito
 
td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020
td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020
td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020Taro L. Saito
 
Airframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpecAirframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpecTaro L. Saito
 
Presto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 UpdatesPresto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 UpdatesTaro L. Saito
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of PrestoTaro L. Saito
 
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataHow To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataTaro L. Saito
 
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Taro L. Saito
 
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Taro L. Saito
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTaro L. Saito
 
Learning Silicon Valley Culture
Learning Silicon Valley CultureLearning Silicon Valley Culture
Learning Silicon Valley CultureTaro L. Saito
 
Presto At Treasure Data
Presto At Treasure DataPresto At Treasure Data
Presto At Treasure DataTaro L. Saito
 
Scala at Treasure Data
Scala at Treasure DataScala at Treasure Data
Scala at Treasure DataTaro L. Saito
 
Presto As A Service - Treasure DataでのPresto運用事例
Presto As A Service - Treasure DataでのPresto運用事例Presto As A Service - Treasure DataでのPresto運用事例
Presto As A Service - Treasure DataでのPresto運用事例Taro L. Saito
 
Treasure Dataを支える技術 - MessagePack編
Treasure Dataを支える技術 - MessagePack編Treasure Dataを支える技術 - MessagePack編
Treasure Dataを支える技術 - MessagePack編Taro L. Saito
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoTaro L. Saito
 
Spark Internals - Hadoop Source Code Reading #16 in Japan
Spark Internals - Hadoop Source Code Reading #16 in JapanSpark Internals - Hadoop Source Code Reading #16 in Japan
Spark Internals - Hadoop Source Code Reading #16 in JapanTaro L. Saito
 

More from Taro L. Saito (19)

Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021Unifying Frontend and Backend Development with Scala - ScalaCon 2021
Unifying Frontend and Backend Development with Scala - ScalaCon 2021
 
Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020
Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020
Journey of Migrating 1 Million Presto Queries - Presto Webinar 2020
 
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
 
Airframe RPC
Airframe RPCAirframe RPC
Airframe RPC
 
td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020
td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020
td-spark internals: Extending Spark with Airframe - Spark Meetup Tokyo #3 2020
 
Airframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpecAirframe Meetup #3: 2019 Updates & AirSpec
Airframe Meetup #3: 2019 Updates & AirSpec
 
Presto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 UpdatesPresto At Arm Treasure Data - 2019 Updates
Presto At Arm Treasure Data - 2019 Updates
 
Reading The Source Code of Presto
Reading The Source Code of PrestoReading The Source Code of Presto
Reading The Source Code of Presto
 
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure DataHow To Use Scala At Work - Airframe In Action at Arm Treasure Data
How To Use Scala At Work - Airframe In Action at Arm Treasure Data
 
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
Airframe: Lightweight Building Blocks for Scala - Scale By The Bay 2018
 
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
Airframe: Lightweight Building Blocks for Scala @ TD Tech Talk 2018-10-17
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS Projects
 
Learning Silicon Valley Culture
Learning Silicon Valley CultureLearning Silicon Valley Culture
Learning Silicon Valley Culture
 
Presto At Treasure Data
Presto At Treasure DataPresto At Treasure Data
Presto At Treasure Data
 
Scala at Treasure Data
Scala at Treasure DataScala at Treasure Data
Scala at Treasure Data
 
Presto As A Service - Treasure DataでのPresto運用事例
Presto As A Service - Treasure DataでのPresto運用事例Presto As A Service - Treasure DataでのPresto運用事例
Presto As A Service - Treasure DataでのPresto運用事例
 
Treasure Dataを支える技術 - MessagePack編
Treasure Dataを支える技術 - MessagePack編Treasure Dataを支える技術 - MessagePack編
Treasure Dataを支える技術 - MessagePack編
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 
Spark Internals - Hadoop Source Code Reading #16 in Japan
Spark Internals - Hadoop Source Code Reading #16 in JapanSpark Internals - Hadoop Source Code Reading #16 in Japan
Spark Internals - Hadoop Source Code Reading #16 in Japan
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Relational-Style XML Query @ SIGMOD-J 2008 Dec.

  • 1. 斉藤 太郎 (Taro L. Saito) 東京大学 2008年12月20日 ACM SIGMOD 日本支部第40回大会 http://www.xerial.org/
  • 2. さあ みんなで SAX, DOM, XMLのプロジェクト XPATH, XQUERY, DTD, XML 我が社にとってXMLは重 を始めることにした SCHEMA, RELAX NG 要だ。今までのテーブル を勉強するんだ! と違って、まったく新し いデータ構造だからな  はっきり言って、たいへんです。 › XMLを使うのにこんなに学ぶことがあるなんて 2
  • 3. XMLのいいところ › テキスト(簡単に扱える) › XMLの方が直観的なデータ構造に近い <Company value=“1”> <Emp value=“e1”> <Office>NY</Office> </Emp> <Emp value=“e2”> Co <Office>NY</Office> </Emp> Company Employee Office </Company> 1 e1 NY Emp Emp 1 e2 NY e1 e2 Relational Data Office Office (テーブルデータ) NY NY XML Data 3
  • 4. XMLに変換されたテーブルデータを取り出したい  例題:テーブルの一行 (Co, Emp, Office) をXML から取り出す › 例えば、XPath(経路を指定して検索する方法)では /Co/Emp/Office と書く Co Co Emp Office 1 e1 NY 1 e2 NY Emp Emp e1 e2 Relational Data Office Office NY NY XML Data 4
  • 5. テーブルからXMLへの変換の仕方は、一通 りではない Co Co Emp Office 1 e1 NY Emp Emp 1 e2 NY e1 e2 Relational Data Co Office Office NY NY Office NY Office NY Co Emp Emp Emp Emp e1 e2 e1 e2 5
  • 6. XML構造全体を把握していないと、構造のゆら ぎのため、正しい経路を指定できない › データベース設計者と利用者の意思疎通が必要 不可欠 Co Co Office NY Emp Emp Office NY e1 e2 Co Emp Emp Emp Emp Office Office e1 e2 e1 e2 NY NY /Office[Co]/Emp /Co/Office/Emp /Co/Emp[Office] [X] : 枝分かれ 6
  • 7.  鍵となる考え方 › Relation(行データ)は、XML Co Emp Office に埋め込まれているだけ 1 e1 NY 1 e2 NY Relational Data Co Co Emp Emp Office NY e1 e2 Office NY Office Office Co Emp Emp NY NY e1 e2 Emp Emp e1 e2 7
  • 9. XMLからrelation(テーブル)を取り出す手法 › 検索にはSQL文を使う  SELECT Co, Emp, Office from (XML Data) Co Co Office Emp Emp Office SQL over NY Input XML Data e1 e2 NY XML! Co Emp Emp Office Office Emp Emp e1 e2 NY NY e1 e2 Co Emp Office 1 e1 NY Result 1 e2 NY  設計者がどんなXML構造を使っていて も、SQL文は影響を受けない 9
  • 10. SQL文 SELECT A, B, C をXMLの構造を検索する問い 合わせに変換する › (A, B, C)のXML表現では、様々な構造のゆらぎが生じ得る A B B A C B C ….. A C B C A B C A  一般に、N個のノードには NN-1 種類の構造のゆ らぎがある 10
  • 11. (A, B, C) が amoeba (アメーバ)構造  A, B, Cのうち、どれか一つが他の親ノー ド(祖先も含む)になっている A B B A C B C ….. A C B C A B C A  Amoeba joinは、すべてのamoeba構造を XMLから取り出す操作. 11
  • 12. Amoebaではあるが、relation(行データ)にはな らない構造がある › なぜ、下図のamoebaがrelationにならないのか?  それは、XMLの構造の中に、functional dependencies (FD) が暗黙に想定されているから 1 company Company M office Office Office 1 N employee Emp Emp Emp Emp ER-diagram (Data Model) 12
  • 13. FD: X -> Y (ノードXからユニークな(たった1つの)ノードY が見つけられる) › employee-> office (各employee は特定のofficeに所属している) › office -> company (各office は、ある会社に属している)  Relation in XML では、個々のFDが、それぞれamoeba構造 をとる必要がある 1 company Company M amoebaに office Office Office なっていない! 1 N employee Emp Emp Emp Emp ER-diagram (Data Model) 13
  • 14.  company に、M 個所のoffice、またそれぞれのoffice にN人のemployeeがいるとすると…  (company, office, employee) の組み合わせの数: › M = 100, N = 5 のとき 100 x (100 x 5) = 50,000  一方、正しい組み合わせの数は M * N = 500 1 company Company M office Office Office Office 1 N Emp Emp Emp Emp employee Emp Emp Emp Emp Emp 14
  • 15. FD: Emp -> Office, Office -> Company  ボトムアップにamoebaを組み立てていく 1. Amoeba Join (Employee, Office) 2. Amoeba Join (Office, Company) 1 company Company M office Office Office Office 1 N Emp Emp Emp Emp employee Emp Emp Emp Emp Emp  FDを考慮すると、関係のない構造をはじくことができる 15
  • 16. FDを考慮したamoeba join › データサイズに比例した性能 16
  • 17. SQLからXMLクエリへ自動変換 › SELECT Co, Office, Emp  FD: Emp -> Office, Office -> Co Co Office Office Co Emp Office Emp ….. Co Emp Office Emp Co Office Emp Co  XMLクエリは、Relation(テーブル構造)とFD から自動的に定まる 17
  • 18. 1対多 (one-to-many) と1対1 (one-to-one) › 例:FD、 Emp -> Office は、以下のような関係に対応:  個々のemployeeは、あるofficeに属している  逆に考えて、officeには、複数の employeeがいる (1対多)  1対1、1対多の関係(FD)を見つけるには、 › XMLデータ中から親子関係にある組の出現頻度を数える › あるいは、ERダイアグラム・UML(データモデル)から直接抽出 Company company 1 M Office office Office 1 N Emp Emp Emp Emp employee 18
  • 19. 「XMLは木構造」という発想から抜け出す › XML := Relation + Annotation  ステップ › 1. XMLデータからRelation(行データ)を見つける › 2. 1対多のFDを見つける › 3. SQLで問い合わせ文を書く company  SELECT Co, Emp, Office c1 annotation employee absent  備考: e1  アノテーションをクエリに含め ることもできる employee office NY e2  一部はXMLのまま、その他は relationという構成も可能 office NY 19
  • 20.  Relation in XML › AmoebaとFDで、構造が決まる  Relational-Style XML Query › SQLを用いて、XMLからrelationを取り出せる › 構造のゆらぎに強い  XMLデータの組み方に自由度が生まれる  Good-bye XPath!! › 目的のXML構造は、パスで指定せずとも、テー ブルスキーマとFDから自動的に決まる 20
  • 21. 技術的な詳細は論文の方に › Relational-Style XML Query. Taro L. Saito, Shinichi Morishita. SIGMOD 2008.  RDBMSと同じ枠組みで実装できる › 問い合わせ代数・クエリの最適化など  データベースの統合にも活用できる  XMLデータのスキーマ変更が容易に › RDBMSのスキーマ拡張とほぼ同じ  Relationalデータに、XMLを使った annotationを付加しやすくなる  …などなど 21
  • 22. 実は「SQLでいける」  よくよく見ると、XMLの中にテーブル構造(relational data)が埋め込まれている場合がほとんど XMLのプロジェクト 我が社にとってXMLは Relational Styleで を始めることにした 重要だ。でも、XMLと 考えれば怖くない!! いってもほとんど テーブルデータなんだ  XML技術の深みにはまる前に… Think in Relational Style!!! 22
  • 23. 23
  • 24. OR (Object-Relational) マッピング › Object-XMLマッピングのサブセット › プログラム言語のクラス定義から、スキーマ定義を抽出  Javaなどのリフレクション機能を用いると全自動 › オブジェクトデータをXMLや、RDBに出力  AmoebaとFDさえ満たしていれば、どのようなXML構造 で出力してもOK › XML・RDBデータを読み込んで、オブジェクトを生成  SAX, DOMでのプログラミングが一切不要になる  他の木構造データにも使える › JSON, YAMLなども扱える › CSVなどテーブル形式のデータでも構わない 24
  • 25. Class定義からrelation & FDを抽出 › Relation: (id, start, end , name) › FD: gene -> id, start, end, name › XML からList<Gene>を取りだす Class Definition (Java) class Gene { <data> private int id; <gene id=“1”> private int start; <start>100</start> private int end; private String name; <end>3000</end> <name>A</name> public Gene(){} </gene> <gene id=“2”> public void setId(int id) { this.id = id; } <start>3500</start> public void setName(String name) <end>7000</end> { this.name = name; } </gene> // followed by other setters </data> …. } 25
  • 26.  Xerial (エクセリアル) Project › XML DBMSの実装、OR・OXマッピング関連 のライブラリなど › http://www.xerial.org/  Relational-Style XML Query › 開発版をオープンソースで公開予定  Apache License Version 2.0 › Javaによる実装  MavenのCentral Repository経由で配布さ れます 26