Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

Disponible en versión 2.2.0-hyperblast

...

  • Los datos tipo string son con ' siempre

  • Los joins, se limitan al uso sólo de inner join y left join. No es válida la sintaxis de múltiples orígenes comas select * from ontology1, ontology2,….

  • El timestamp desde string cambia de timestamp '' a la función to_timestamp('')

  • El $oid desde string cambia de OID '' a la función OID('') o toObjectId('')

  • Las proyecciones de array u objetos tipo .* .0 [2] [*] {*} no están soportadas, es posible su implementación con funciones

  • No se puede concatenar con ||, hay que usar la función concat()

  • No se puede usar el alias o el nombre de la ontologías para hacer las proyecciones ni con *. Serían incorrectas estas queries (en su lugar hay que usar select * from Ontology):

SELECT c FROM Ontology AS c LIMIT 3

SELECT c.* FROM Ontology AS c LIMIT 3

SELECT Ontology FROM Ontology AS c LIMIT 3

SELECT Ontology.* FROM Ontology AS c LIMIT 3

Consideraciones del ObjectID y el _id

...

Extensibilidad del nuevo motor SQL de mongo

Sintaxis

Data Types

Type

Description

Examples

Null

Indicates missing information.

null

Boolean

true or false

truefalse

Integer

Whole numbers (no fractional component)

1-2

Decimal

Decimal numbers (optional fractional components)

1.0-2.19743

String

Text

'221B Baker Street'

DateTime

Date and time, in ISO8601 format

to_timestamp('2004-10-19T10:23:54Z')

Object ID

Unique object identifier.

OID('507f1f77bcf86cd799439011')

Clauses

The following clauses are supported:

Type

Clauses

Basic

SELECTASFROM

Joins

LEFT JOININNER JOINJOIN

Filtering

WHERE

Grouping

GROUP BYHAVING

Subquery

FROM (SELECT ...) AS

Paging

LIMITOFFSET

Sorting

ORDER BY , DESCASC

Conditional

CASE WHEN ELSE

The following operators are supported:

Type

Operators

String

LIKENOT LIKE

Relational

=>=<=<>INNOT IN

Boolean

ANDORNOT

Null

IS NULLIS NOT NULL

Projection

foo.bar

Mathematical

+, -, *, /, %

The following functions are supported by default (this can be extended with new functions). Those are case insensitive:

Type

Functions

String

CONCATLOWERUPPERSUBSTRINGLENGTH

DateTime

DATE_PARTTO_TIMESTAMP

Arrays

UNZIP (only in project)ELEMAT

Geo

GEOWITHIN (only in where)

Set-Level

DISTINCT

Aggregation

COUNTSUMMINMAXAVG, FIRST, LAST, COUNT(DISTINCT ...)

Conversion

TOINT, TOBOOL, TOSTRING, TOOBJECTID (or OID), TODOUBLE,TOLONG, TODATE, TODECIMAL

Timeserie

UNZIPTS (only in project)

Ejemplos de uso

Queries Básicas:

...

Se dispone de varias funciones incluidas en el motor por defecto (estas son ampliables mediante configuración). Se usan en modo case insensitive por lo que pueden escribirse indistintamente en mayúsculas o minúsculas:

Type

Name

Params

Places

Example

Comments

String

CONCAT

1..* String or column with type string

all

select concat('Cuisine ', c.Restaurant.cuisine) from Restaurants as c

Return combination of all strings

String

LOWER, UPPER

1 String or column with type string

all

select concat('Cuisine ', upper(c.Restaurant.cuisine)) from Restaurants as c

lowercase/uppercase of string

String

SUBSTRING

3 String or column with type string, index (integer), length (integer)

all

select concat('Cuisine ', substring(c.Restaurant.cuisine,2,3)) from Restaurants as c

substring of string

String

LENGTH

1 String or column with type string

all

select length(c.Restaurant.cuisine) from Restaurants as c

length of string

String

TRIM

1 String or column with type string

all

SELECT trim(' aaa '), trim(c.Restaurant.borough) FROM Restaurants AS c LIMIT 300

trim a string

DateTime

DATE_PART

2 part type ("month","year","dayOfMonth","hour","minute","second",
"millisecond","dayOfYear","dayOfWeek","week"), timestamp or field with timestamp type

all

SELECT date_part('year',timestamp) as year, date_part('month',timestamp) as month FROM QA_DETAIL AS c LIMIT 3

SELECT date_part('dayOfMonth',timestamp) as day, count(*) FROM QA_DETAIL AS c group by day

get date part from timestamp

DateTime

TO_TIMESTAMP/TIMESTAMP

1 timestamp or field with timestamp type

all

SELECT timestamp FROM QA_DETAIL AS c where timestamp > to_timestamp('2018-10-24T23:00:00.000Z') LIMIT 3

SELECT timestamp FROM QA_DETAIL AS c where timestamp > timestamp('2018-10-24T23:00:00.000Z') LIMIT 3

convert string to timestamp

Arrays

UNZIP

2 array type field, boolean (preserve null and empty arrays in unzip)

project

select unzip(Restaurant.grades,true) from Restaurants

unzip array in multiple instances. Second param enable/disable preserve null and empty arrays. This function can only be used alone in project because of the changing of the number of records. All filters applied are before unzip. You can use this in a subquery for continue operating over array

Arrays

ELEMAT

1 array type field

all

select elemat(Restaurant.grades,1) from Restaurants

get element by position in array

Geo

GEOWITHIN

2 geometry point field, geometry

where

select * from Supermarkets where geoWithin(Supermarkets.geometry, '{type : "Polygon" , coordinates: [ [ [-15.44488, 28.137924], [-15.423848, 28.137924], [-15.423848, 28.144054], [-15.44488, 28.144054], [-15.44488, 28.137924] ] ] }')

find some geometry field point in geometry structure as the second arguments. Only in where because mongoDB limitation

Aggregation

COUNT

1 field or *

project or having

select count(*) from Supermarkets

count

Aggregation

SUM, MIN, MAX, AVG, FIRST, LAST

1 field (type depending on operation)

project or having

select min(c.Supermarkets.status) as maxs from Supermarkets as c

aggregation functions. Last and first get first or last of a group

Conversion

TOINT, TOBOOL, TOSTRING, TOOBJECTID (or OID), TODOUBLE,TOLONG, TODATE, TODECIMAL

1 field (type depending on operation)

all

select concat('Cuisine ', UPPER(c.Restaurant.cuisine), ' of length ',toString(length(UPPER(c.Restaurant.cuisine)))) as complex from Restaurants as c

conversion between type

Timeserie

UNZIPTS

2 window type in String (uppercase), window frequency in String (uppercase)

project

SELECT unzipts('DAYS','MINUTES') FROM timeserie AS c LIMIT 3

unzip timeserie into plain strcture returning the instances like when they're inserted. This function can only be used alone in project because of the changing of the number of records. All filters applied are before unzipts. You can use this in a subquery for continue operating over timeserie

Trabajo futuro

...

Posibilidad de uso de unions (sólo mongo 4.4 en adelante)

...

Uso de subqueries en where

...

Count Distinct clause (Desde 4.2.1-predator)

Con esta clausula puedes realizar la operación de conteo de distintos valores de un grupo (el incluido en el distinct) para otro grupo dado (el que está fuera del distinct)

select count(distinct Restaurant.borough) from Restaurants

...

select Restaurant.cuisine, count(distinct Restaurant.borough, Restaurant.name) from Restaurants

...

Por restricciones del lenguaje de consultas de mongodb, no esta permitido la combinación con otros elementos diferentes de columnas.