SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
TreSQL (Tree SQL)

     Mārtiņš Rumovskis
Agenda
   Motivation

   TreSQL vs SQL

   TreSQL statement structure

   Scala API
Agenda
   Motivation

   TreSQL vs SQL

   TreSQL statement structure

   Scala API
Old Good SQL
   Traditionally we can get data in the tabular form
        DEPTNO     DNAME      LOC
        30         SALES      Chicago
Old Good SQL
   Traditionally we can get data in the tabular form
        DEPTNO     DNAME       LOC
        30         SALES       Chicago




   But we need something like this...
        DEPTNO   DNAME      LOC          EMPNO   ENAME
        30       SALES      Chicago      1       ALLEN
                                         2       WARD
                                         3       MARTIN
        20       RESEARCH   Dallas       4       MILLER
                                         5       SCOTT
Old Good SQL
   Traditionally we can get data in the tabular form
         DEPTNO          DNAME        LOC
         30              SALES        Chicago




   But we need somethink like this...
        DEPTNO        DNAME        LOC          EMPNO   ENAME
        30            SALES        Chicago      1       ALLEN
                                                2       WARD
                                                3       MARTIN
        20            RESEARCH     Dallas       4       MILLER
                                                5       SCOTT



   Or like this...
        NAME          DRIVER_LIC    LANGUAGES
        SCOTT         A,B           EN,LV,RU
        MILLER        B,C           EN,IT
Old Good SQL (Cont)
   We need to write joins
       select * from emp e join dept d on e.deptno = d.deptno
Old Good SQL (Cont)
   We need to write joins
       select * from emp e join dept d on e.deptno = d.deptno



   Explicitly specify id column name
       select * from dept where id in (10, 20, 30)
Problems of JDBC
   JDBC
       We need to do SQL to Java mappings
        setXXX(idx, value)
                         ...well you know
       We need to bind every variable in the SQL statement noted as
        ‘?’ otherwise exception occurs
Problems of JDBC
   JDBC
       We need to do SQL to Java mappings
        setXXX(idx, value)
                         ...well you know


       We cannot run several queries
            select * from dept where deptno = 10,
            select * from emp where job = 'MGR'
What’s about ORM?
   ORM (Hibernate)

       We need to define class model and mapping
What’s about ORM?
   ORM (Hibernate)

       We need to define class model and mapping

       And we still need SQL (for advanced use) 
Agenda
   Motivation

   TreSQL vs SQL

   TreSQL statement structure

   Scala API
Sql vs TreSQL


   Simple SQL
    SQL: select * from dept
Sql vs TreSQL


   Simple SQL
    SQL: select * from dept


    TreSQL:      dept
Sql vs TreSQL


   Select... Where
    SQL: select * from dept where deptno = 10
Sql vs TreSQL


   Select... Where
    SQL: select * from dept where deptno = 10


    TreSQL:       dept[10]
Sql vs TreSQL


   More complex select
    SQL: select deptno, dname from dept
           select ename from emp where deptno = :deptno
Sql vs TreSQL


   More complex select (needs programming when using
    SQL)
    SQL: select deptno, dname from dept
           select ename from emp where deptno = :deptno

    TreSQL: dept{deptno, dname,
            |emp[:1(1) = deptno] {ename} employees}
Sql vs TreSQL


   Multiple selects
    SQL: select * from dept where deptno = 10
         select * from emp where job = 'MGR'
Sql vs TreSQL


   Multiple selects
    SQL: select * from dept where deptno = 10
         select * from emp where job = 'MGR‘

    TreSQL:       dept[10], emp[job = 'MGR']
Sql vs TreSQL


   Outer join order by

    SQL: select * from dept
            left join emp on dept.deptno = emp.deptno
            order by dname
Sql vs TreSQL


   Outer join order by

    SQL: select * from dept
              left join emp on dept.deptno = emp.deptno
              order by dname

    TreSQL:        dept/emp? #(dname)
Sql vs TreSQL


   In, subselect
    SQL: select * from dept where deptno
              in (select deptno from emp)
Sql vs TreSQL


   In, subselect
    SQL: select * from dept where deptno
              in (select deptno from emp)

    TreSQL:         dept [deptno in (emp{deptno})]
Sql vs TreSQL


   Exists, correlated subselect
    SQL: select * from dept d where
             exists select * from emp e
                 where d.deptno = e.deptno
Sql vs TreSQL


   Exists, correlated subselect
    SQL: select * from dept d where
             exists select * from emp e
                 where d.deptno = e.deptno

    TreSQL:       dept d[(emp e[e.deptno = d.deptno])]
Sql vs TreSQL

   More complex example (using SQL programming is
    needed)

    dept{deptno, dname,
         |emp[sal >= hisal & sal <= losal]salgrade[deptno =
                                                    :1(1)]
          {grade, hisal, losal, count(empno) empcount,
             |emp/dept[sal >= :1(2) & sal <= :1(3) &
                       emp.deptno = :2(1)]
              {ename, emp.deptno, dname, sal}#(empno) emps
          } (grade, hisal, losal) #(1) salgrades
        } #(deptno)
Agenda
   Motivation

   TreSQL vs SQL

   TreSQL statement structure

   Scala API
TreSQL Language Structure


   SELECT statement structure
    <from>[<where>][<columns>][<group by>
    [<having>]][<order>][<offset> [<limit>]]


    table1[join cond]table2[where]{columns} (group
    cols)^(having expr) #(order) (offset limit)
TreSQL Language Structure


   INSERT
    DEPT {DEPTNO, DNAME, LOC}
        + [10, "ACCOUNTING", "NEW YORK"]



   Statement structure
    table {col1, col2} + [val1, val2]
TreSQL Language Structure


   UPDATE
    emp[1] {ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO} =
    [?, ?, ?, ?, ?, ?, ?]



   Statement structure

    table [where] {col1, col2} = [val1, val2]
TreSQL Language Structure


   DELETE
    emp - [1]




   Statement structure
    table - [where]
Agenda
   Motivation

   TreSQL vs SQL

   TreSQL statement structure

   Scala API
Scala API
    Code example:
import org.tresql._

Env update connection

Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}

//

val expr = Query.build("emp[deptno = ?]{*}")

val result = expr.select(10)

result foreach println

expr close

Jsonizer.jsonize(Query(expr, pars), writer, rType)
Scala API
    Code example:
import org.tresql._       org.tresql.Env
                          Expression execution environment. Used for setting
                          database connection.
Env update connection

Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}

//

val expr = Query.build("emp[deptno = ?]{*}")

val result = expr.select(10)

result foreach println

expr close
Scala API
    Code example:
import org.tresql._

Env update connection

Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}

//                       org.tresql.Query
                         Expression execution, result iteration

val expr = Query.build("emp[deptno = ?]{*}")

val result = expr.select(10)

result foreach println

expr close
Scala API
    Code example:
import org.tresql._

Env update connection

Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}

                         org.tresql.Expr
//                       Builded expression. Equivalent to java.sql.PreparedStatement

val expr = Query.build("emp[deptno = ?]{*}")

val result = expr.select(10)

result foreach println

expr close
Scala API
    Code example:
import org.tresql._

Env update connection

Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}

//

val expr = Query.build("emp[deptno = ?]{*}")

val result = expr.select(10)
                                          org.tresql.Expr
result foreach println                    Expression result – org.tresql.Result

expr close
Scala API
    Code example:
import org.tresql._

org.tresql.Env update connection

org.tresql.Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}

//

val expr = Query.build("emp[deptno = ?]{*}")

val result = expr.select(10)

                                   org.tresql.Expr
result foreach println
                                   Result JSON formatting

expr close

Jsonizer.jsonize(Query(expr, pars), writer, rType)
Scala API
   Code example:
import org.tresql._

org.tresql.Env update connection

org.tresql.Query.foreach("emp[sal > ? & deptno = ?]", 1000, 10) {row=>
                                                            println(row(0))}

org.tresql.Query.foreach("emp[sal > ? & deptno = ?]", 1000) {row=>
                                                            println(row(0))}




                                              org.tresql.Expr
                                              Optional binding
That’s about it!




                   Visit: https://github.com/mrumkovskis/Query
Q&A

Weitere ähnliche Inhalte

Was ist angesagt?

Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
Mario Fusco
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
Mike Fogus
 

Was ist angesagt? (18)

Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev FedorProgramming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
Programming Java - Lection 04 - Generics and Lambdas - Lavrentyev Fedor
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
 
Mobile Fest 2018. Александр Корин. Болеутоляющее
Mobile Fest 2018. Александр Корин. БолеутоляющееMobile Fest 2018. Александр Корин. Болеутоляющее
Mobile Fest 2018. Александр Корин. Болеутоляющее
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCode
 
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
Lucio Floretta - TensorFlow and Deep Learning without a PhD - Codemotion Mila...
 
Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
 
Parsing with Perl6 Grammars
Parsing with Perl6 GrammarsParsing with Perl6 Grammars
Parsing with Perl6 Grammars
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwo
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
What's new in C# 6 - NetPonto Porto 20160116
What's new in C# 6  - NetPonto Porto 20160116What's new in C# 6  - NetPonto Porto 20160116
What's new in C# 6 - NetPonto Porto 20160116
 

Ähnlich wie TreSQL

ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
alexstorer
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
Raimonds Simanovskis
 

Ähnlich wie TreSQL (20)

Beg sql
Beg sqlBeg sql
Beg sql
 
Beg sql
Beg sqlBeg sql
Beg sql
 
JDBC for CSQL Database
JDBC for CSQL DatabaseJDBC for CSQL Database
JDBC for CSQL Database
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
SQL introduction
SQL introductionSQL introduction
SQL introduction
 
Getting Functional with Scala
Getting Functional with ScalaGetting Functional with Scala
Getting Functional with Scala
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
 
Python database access
Python database accessPython database access
Python database access
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schools
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Ss dotnetcodexmpl
Ss dotnetcodexmplSs dotnetcodexmpl
Ss dotnetcodexmpl
 
Scala basic
Scala basicScala basic
Scala basic
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
User Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love StoryUser Defined Aggregation in Apache Spark: A Love Story
User Defined Aggregation in Apache Spark: A Love Story
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Jdbc ja
Jdbc jaJdbc ja
Jdbc ja
 

Mehr von Dmitry Buzdin

Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
Dmitry Buzdin
 
Архитектура Ленты на Одноклассниках
Архитектура Ленты на ОдноклассникахАрхитектура Ленты на Одноклассниках
Архитектура Ленты на Одноклассниках
Dmitry Buzdin
 
Riding Redis @ask.fm
Riding Redis @ask.fmRiding Redis @ask.fm
Riding Redis @ask.fm
Dmitry Buzdin
 
Rubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part IIRubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part II
Dmitry Buzdin
 
Rubylight Pattern-Matching Solutions
Rubylight Pattern-Matching SolutionsRubylight Pattern-Matching Solutions
Rubylight Pattern-Matching Solutions
Dmitry Buzdin
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional Programming
Dmitry Buzdin
 
Rubylight programming contest
Rubylight programming contestRubylight programming contest
Rubylight programming contest
Dmitry Buzdin
 
Continuous Delivery
Continuous Delivery Continuous Delivery
Continuous Delivery
Dmitry Buzdin
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
Dmitry Buzdin
 
Thread Dump Analysis
Thread Dump AnalysisThread Dump Analysis
Thread Dump Analysis
Dmitry Buzdin
 

Mehr von Dmitry Buzdin (20)

How Payment Cards Really Work?
How Payment Cards Really Work?How Payment Cards Really Work?
How Payment Cards Really Work?
 
Как построить свой фреймворк для автотестов?
Как построить свой фреймворк для автотестов?Как построить свой фреймворк для автотестов?
Как построить свой фреймворк для автотестов?
 
How to grow your own Microservice?
How to grow your own Microservice?How to grow your own Microservice?
How to grow your own Microservice?
 
How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?
 
Delivery Pipeline for Windows Machines
Delivery Pipeline for Windows MachinesDelivery Pipeline for Windows Machines
Delivery Pipeline for Windows Machines
 
Big Data Processing Using Hadoop Infrastructure
Big Data Processing Using Hadoop InfrastructureBig Data Processing Using Hadoop Infrastructure
Big Data Processing Using Hadoop Infrastructure
 
JOOQ and Flyway
JOOQ and FlywayJOOQ and Flyway
JOOQ and Flyway
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
 
Whats New in Java 8
Whats New in Java 8Whats New in Java 8
Whats New in Java 8
 
Архитектура Ленты на Одноклассниках
Архитектура Ленты на ОдноклассникахАрхитектура Ленты на Одноклассниках
Архитектура Ленты на Одноклассниках
 
Dart Workshop
Dart WorkshopDart Workshop
Dart Workshop
 
Riding Redis @ask.fm
Riding Redis @ask.fmRiding Redis @ask.fm
Riding Redis @ask.fm
 
Rubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part IIRubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part II
 
Rubylight Pattern-Matching Solutions
Rubylight Pattern-Matching SolutionsRubylight Pattern-Matching Solutions
Rubylight Pattern-Matching Solutions
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional Programming
 
Rubylight programming contest
Rubylight programming contestRubylight programming contest
Rubylight programming contest
 
Continuous Delivery
Continuous Delivery Continuous Delivery
Continuous Delivery
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 
Thread Dump Analysis
Thread Dump AnalysisThread Dump Analysis
Thread Dump Analysis
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

TreSQL

  • 1. TreSQL (Tree SQL) Mārtiņš Rumovskis
  • 2. Agenda  Motivation  TreSQL vs SQL  TreSQL statement structure  Scala API
  • 3. Agenda  Motivation  TreSQL vs SQL  TreSQL statement structure  Scala API
  • 4. Old Good SQL  Traditionally we can get data in the tabular form DEPTNO DNAME LOC 30 SALES Chicago
  • 5. Old Good SQL  Traditionally we can get data in the tabular form DEPTNO DNAME LOC 30 SALES Chicago  But we need something like this... DEPTNO DNAME LOC EMPNO ENAME 30 SALES Chicago 1 ALLEN 2 WARD 3 MARTIN 20 RESEARCH Dallas 4 MILLER 5 SCOTT
  • 6. Old Good SQL  Traditionally we can get data in the tabular form DEPTNO DNAME LOC 30 SALES Chicago  But we need somethink like this... DEPTNO DNAME LOC EMPNO ENAME 30 SALES Chicago 1 ALLEN 2 WARD 3 MARTIN 20 RESEARCH Dallas 4 MILLER 5 SCOTT  Or like this... NAME DRIVER_LIC LANGUAGES SCOTT A,B EN,LV,RU MILLER B,C EN,IT
  • 7. Old Good SQL (Cont)  We need to write joins select * from emp e join dept d on e.deptno = d.deptno
  • 8. Old Good SQL (Cont)  We need to write joins select * from emp e join dept d on e.deptno = d.deptno  Explicitly specify id column name select * from dept where id in (10, 20, 30)
  • 9. Problems of JDBC  JDBC  We need to do SQL to Java mappings setXXX(idx, value) ...well you know  We need to bind every variable in the SQL statement noted as ‘?’ otherwise exception occurs
  • 10. Problems of JDBC  JDBC  We need to do SQL to Java mappings setXXX(idx, value) ...well you know  We cannot run several queries select * from dept where deptno = 10, select * from emp where job = 'MGR'
  • 11. What’s about ORM?  ORM (Hibernate)  We need to define class model and mapping
  • 12. What’s about ORM?  ORM (Hibernate)  We need to define class model and mapping  And we still need SQL (for advanced use) 
  • 13. Agenda  Motivation  TreSQL vs SQL  TreSQL statement structure  Scala API
  • 14. Sql vs TreSQL  Simple SQL SQL: select * from dept
  • 15. Sql vs TreSQL  Simple SQL SQL: select * from dept TreSQL: dept
  • 16. Sql vs TreSQL  Select... Where SQL: select * from dept where deptno = 10
  • 17. Sql vs TreSQL  Select... Where SQL: select * from dept where deptno = 10 TreSQL: dept[10]
  • 18. Sql vs TreSQL  More complex select SQL: select deptno, dname from dept select ename from emp where deptno = :deptno
  • 19. Sql vs TreSQL  More complex select (needs programming when using SQL) SQL: select deptno, dname from dept select ename from emp where deptno = :deptno TreSQL: dept{deptno, dname, |emp[:1(1) = deptno] {ename} employees}
  • 20. Sql vs TreSQL  Multiple selects SQL: select * from dept where deptno = 10 select * from emp where job = 'MGR'
  • 21. Sql vs TreSQL  Multiple selects SQL: select * from dept where deptno = 10 select * from emp where job = 'MGR‘ TreSQL: dept[10], emp[job = 'MGR']
  • 22. Sql vs TreSQL  Outer join order by SQL: select * from dept left join emp on dept.deptno = emp.deptno order by dname
  • 23. Sql vs TreSQL  Outer join order by SQL: select * from dept left join emp on dept.deptno = emp.deptno order by dname TreSQL: dept/emp? #(dname)
  • 24. Sql vs TreSQL  In, subselect SQL: select * from dept where deptno in (select deptno from emp)
  • 25. Sql vs TreSQL  In, subselect SQL: select * from dept where deptno in (select deptno from emp) TreSQL: dept [deptno in (emp{deptno})]
  • 26. Sql vs TreSQL  Exists, correlated subselect SQL: select * from dept d where exists select * from emp e where d.deptno = e.deptno
  • 27. Sql vs TreSQL  Exists, correlated subselect SQL: select * from dept d where exists select * from emp e where d.deptno = e.deptno TreSQL: dept d[(emp e[e.deptno = d.deptno])]
  • 28. Sql vs TreSQL  More complex example (using SQL programming is needed) dept{deptno, dname, |emp[sal >= hisal & sal <= losal]salgrade[deptno = :1(1)] {grade, hisal, losal, count(empno) empcount, |emp/dept[sal >= :1(2) & sal <= :1(3) & emp.deptno = :2(1)] {ename, emp.deptno, dname, sal}#(empno) emps } (grade, hisal, losal) #(1) salgrades } #(deptno)
  • 29. Agenda  Motivation  TreSQL vs SQL  TreSQL statement structure  Scala API
  • 30. TreSQL Language Structure  SELECT statement structure <from>[<where>][<columns>][<group by> [<having>]][<order>][<offset> [<limit>]] table1[join cond]table2[where]{columns} (group cols)^(having expr) #(order) (offset limit)
  • 31. TreSQL Language Structure  INSERT DEPT {DEPTNO, DNAME, LOC} + [10, "ACCOUNTING", "NEW YORK"]  Statement structure table {col1, col2} + [val1, val2]
  • 32. TreSQL Language Structure  UPDATE emp[1] {ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO} = [?, ?, ?, ?, ?, ?, ?]  Statement structure table [where] {col1, col2} = [val1, val2]
  • 33. TreSQL Language Structure  DELETE emp - [1]  Statement structure table - [where]
  • 34. Agenda  Motivation  TreSQL vs SQL  TreSQL statement structure  Scala API
  • 35. Scala API  Code example: import org.tresql._ Env update connection Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))} // val expr = Query.build("emp[deptno = ?]{*}") val result = expr.select(10) result foreach println expr close Jsonizer.jsonize(Query(expr, pars), writer, rType)
  • 36. Scala API  Code example: import org.tresql._ org.tresql.Env Expression execution environment. Used for setting database connection. Env update connection Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))} // val expr = Query.build("emp[deptno = ?]{*}") val result = expr.select(10) result foreach println expr close
  • 37. Scala API  Code example: import org.tresql._ Env update connection Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))} // org.tresql.Query Expression execution, result iteration val expr = Query.build("emp[deptno = ?]{*}") val result = expr.select(10) result foreach println expr close
  • 38. Scala API  Code example: import org.tresql._ Env update connection Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))} org.tresql.Expr // Builded expression. Equivalent to java.sql.PreparedStatement val expr = Query.build("emp[deptno = ?]{*}") val result = expr.select(10) result foreach println expr close
  • 39. Scala API  Code example: import org.tresql._ Env update connection Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))} // val expr = Query.build("emp[deptno = ?]{*}") val result = expr.select(10) org.tresql.Expr result foreach println Expression result – org.tresql.Result expr close
  • 40. Scala API  Code example: import org.tresql._ org.tresql.Env update connection org.tresql.Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))} // val expr = Query.build("emp[deptno = ?]{*}") val result = expr.select(10) org.tresql.Expr result foreach println Result JSON formatting expr close Jsonizer.jsonize(Query(expr, pars), writer, rType)
  • 41. Scala API  Code example: import org.tresql._ org.tresql.Env update connection org.tresql.Query.foreach("emp[sal > ? & deptno = ?]", 1000, 10) {row=> println(row(0))} org.tresql.Query.foreach("emp[sal > ? & deptno = ?]", 1000) {row=> println(row(0))} org.tresql.Expr Optional binding
  • 42. That’s about it! Visit: https://github.com/mrumkovskis/Query
  • 43. Q&A