Your SlideShare is downloading. ×
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
TreSQL
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

TreSQL

1,021

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,021
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 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 connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr closeJsonizer.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 connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr close
  • 37. Scala API Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}// org.tresql.Query Expression execution, result iterationval expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr close
  • 38. Scala API Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))} org.tresql.Expr// Builded expression. Equivalent to java.sql.PreparedStatementval expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10)result foreach printlnexpr close
  • 39. Scala API Code example:import org.tresql._Env update connectionQuery.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10) org.tresql.Exprresult foreach println Expression result – org.tresql.Resultexpr close
  • 40. Scala API Code example:import org.tresql._org.tresql.Env update connectionorg.tresql.Query.foreach("dept[?]{dname}", 10) {row=> println(row(0))}//val expr = Query.build("emp[deptno = ?]{*}")val result = expr.select(10) org.tresql.Exprresult foreach println Result JSON formattingexpr closeJsonizer.jsonize(Query(expr, pars), writer, rType)
  • 41. Scala API Code example:import org.tresql._org.tresql.Env update connectionorg.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

×