【LEC207 LEC25 26】

LEC 25-26

XQuery--Extension of XPath by SQL-like features

>> Every XPath expression is an XQuery expression

>> More general XQueries: FLWR expressions

Let clauses:

>> Format :  let variable := XQuery expression

>> 将XQuery表达式的结果赋给变量

Example :

◦let $doc := doc("students.xml")

◦let $student_names := $doc/students/student/name

>> Variable names : start with $ ($doc, $x, $student....)

For clauses:

>> Format : for variable in XQuery expression

>> 依次考虑XQuery表达式结果中的每个项(顺序与结果相同)

Example : 

◦for $s in $doc/students/student

◦for $name in $doc//student[module="COMP207"]/name

Where clauses : 和sql里的差不多,都是接condition

Other types of conditions :

例子:

 

 

下面那个答案错了 应该是

<pair>

    <name>Anna</name>,<id>123456</id>

</pair>

 这里修改也错了,应该是:

for $author in $b/author

return<pair>{$b/title},{$author}</pair>

output是:

<pair><title>...</title>,<author>Anna</author></pair>

<pair><title>...</title>,<author>Ben</author></pair>

 

Order by clauses :  like in sql

 order by 的位置在for&let,where 下面,return 上面

Group by clauses : similar to sql

  Distinct-values

 In SQL it was a key word (DISTINCT)  就是只要不同的值,相同的就不要 

 In XQuery, it is a function, called distinct-values   Converts elements to strings

XML in SQL

Three general approaches to storing XML documents in a relational database :

◦Store XML documents as entries of a table

◦Store XML documents in schema-independent form

◦Store XML documents in shredded form across a number of attributes and relations

>> Creating Table using XML Type

 Introduction to NoSQL

NoSQL : not only mysql

满足典型web应用程序的需求 :

◦Very fast access to data, with millions of users in parallel

◦Fault-tolerance 容错率

◦Flexibility in the type of data stored (semi-structured)

◦Full ACID compliance can sometimes be relaxed

 The CAP Theorem 

 NoSQL Database Classification

Key-Value stores 

Simple access mechanism :

1. find(k): returns value for key k

2. write(k, v): inserts value v under key k

Distributed Storage

>> Three properties :

1. Scalability Via Horizontal Fragmentation

New node can be added easily :

Add node to free range(s) and move key-value pairs appropriately

◦Automatic horizontal fragmentation

2. Availablility via Replication:

Replication is used to ensure availability

Replicas (copies of key-value pairs) are stored on consecutive nodes on the ring in clock-wise order

3. High performance

Retrieving the value for a key is fast: apply the hash function to determine the node, then ask the node

Writing is fast, too.

>> Eventual Consistency

Document stores

Document = semistructured data associated with an object ID

XML vs JSON

>> XML :  

>> JSON : 

Use case : 

 

Case Study: MongoDB

Create collections / insert documents / finding documents

Indexes in MongoDB

​​​​​​​ 

MongoDB Techniques 

 

Column Stores

 Uses two levels of fragmentation:

◦Top level: rows are divided into regions (i.e., ranges of rows)

◦Bottom level: regions store different column families in different nodes (i.e., computers)

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值