DGRAPH basic query syntax 3

Source: Internet
Author: User

This part mainly involves query blocks, query variables, and aggregation operations.

Multi-name query

It is similar to splicing multiple query data.

Format: {Caro (FUNC: allofterms ([email protected], "Marc caro") {[email protected] Director. film {[email protected]} Jeunet (FUNC: allofterms ([email protected], "Jean-Pierre Jeunet") {[email protected] Director. film {[email protected] }}}
Query Variables

It is similar to the input variable of graphql, but it is more convenient to query the variable. It can be understood as the SQL stored procedure or a function in programming.

var_name as some_block { ... }
Query reference of variable data

The data for querying variables can be passed to the subquery block, which is more convenient than graphql.

Reference format: {coactors (FUNC: allofterms ([email protected], "Jane Campion") @ cascade {jc_films as director. film {# jc_films = all Jane Campion's films starting_movie: [email protected] starring {jc_actors as performance. actor {# jc_actors = all actors in all JC films actor: [email protected] actor. film {performance. film @ filter (not UID (jc_films) {film_together: [email protected] starring {# Find A coactor who has been in some JC film performance. actor @ filter (UID (jc_actors) {coactor_name: [email protected] }}}}}}
Variable (min max)

Min Max can be used to obtain the maximum or minimum value of a variable.

Reference format: {q (FUNC: allofterms ([email protected], "Ang Lee") {director. film {uid [email protected] # count the number of starring edges for each film num_actors as Count (starring) # in this block, num_actors is the value calculated for this film. # The film with UID and name} # Here num_actors is a map of film UID to value for all # of Ang Lee's films # It can't be used directly, but aggregations like Min and Max # work over all the values in the map most_actors: max (Val (num_actors)} # To use num_actors in another query, make sure it's done in a context # Where the film UID to value map makes sense .}
Sum AVG)

Get the sum and AVG of the variable.

Reference format: {ID as VAR (FUNC: allofterms ([email protected], "Steven Spielberg") {# Count the actors and save to a variable # average ...} # average is a map from UID to value so it must be used in a context # Where the map makes sense. because query block AVS works over the UID # of Steven Spielberg, the value variable has the value we perform CT. AVS (FUNC: UID (ID) @ normalize {Name: [email protected] # Get the average # also count the movies }}
The variable filter order.

The filter and order operations can be applied to variables.

Reference format: {ID as VAR (FUNC: allofterms ([email protected], "Steven") {director. film {num_actors as Count (starring)} average as AVG (Val (num_actors)} AVS (FUNC: UID (ID), orderdesc: Val (average )) @ filter (Ge (Val (average), 40) @ normalize {Name: [email protected] average_actors: Val (average) num_films: Count (director. film )}}
The variable math.

DGRAPH has built-in Math Function operations, which can be used for common ++/-And sin .... Operation

Reference format: {VAR (FUNC: allofterms ([email protected], "Jean-Pierre Jeunet") {[email protected] films as director. film {stars as Count (starring) directors as Count (~ Director. film) ratio as math (STARS/Directors)} best_ratio (FUNC: UID (films), orderdesc: Val (ratio) {[email protected] stars_per_director: Val (ratio) num_stars: Val (stars )}}
Groupby operation

Similar to the groupby operation of SQL, the internal operation of the groupby code block can only be applied to aggregate functions, and count can only
Apply to uid, and easily apply variables to other queries

Reference format: {VAR (FUNC: allofterms ([email protected], "Steven Spielberg") {director. film @ groupby (genre) {A as Count (UID)} bygenre (FUNC: UID (A), orderdesc: Val (A) {[email protected] num_movies: val ()}}
References

Https://tour.dgraph.io/blocksvars/1/
Https://github.com/rongfengliang/dgraph-docker-compose-deploy

DGRAPH basic query syntax 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.