Query Languages for Data
When the relational model was introduced, it changed how we query data from imperative to declarative.
Declarative vs. Imperative
- Imperative: You tell the computer how to perform a task (step-by-step logic, loops).
- Declarative: You specify the pattern of the data you want, but not how to achieve it.
The CSS Analogy
Declarative languages are not limited to databases. Consider a web browser:
- Declarative (CSS):
li.selected > p { background: blue; }. You describe what should be blue. The browser handles the implementation and updates. - Imperative (JavaScript): You would have to loop through all
lielements, check for the class, find the childp, and set the color. If the class changes later, you must manually update it again.
MapReduce Querying
MapReduce is a mix: the logic is expressed with snippets of code (map and reduce), but the framework handles the execution across machines. It is lower-level than SQL but more flexible for certain tasks.
Knowledge Check
Why are declarative query languages generally better for parallel execution?
Because they specify the exact algorithm to use.
Because they specify what to achieve, allowing the engine to pick the best implementation.
Because they are written in JavaScript.