### Plugin Installation Example Source: https://trino.io/docs/current/installation/plugins.html Demonstrates the process of installing a plugin by extracting its ZIP archive and placing it in the Trino 'plugin' directory. ```bash # Assuming 'example-plugin-1.0.zip' is extracted and renamed to 'example-plugin' # Copy the 'example-plugin' directory into Trino's plugin directory cp -R example-plugin /path/to/trino/installation/plugin/ ``` -------------------------------- ### Example Kubernetes Resource Output Source: https://trino.io/docs/current/installation/kubernetes.html This is an example of the expected output when running 'kubectl get all' after a successful Trino deployment. ```text NAME READY STATUS RESTARTS AGE pod/example-trino-cluster-coordinator-bfb74c98d-rnrxd 1/1 Running 0 161m pod/example-trino-cluster-worker-76f6bf54d6-hvl8n 1/1 Running 0 161m pod/example-trino-cluster-worker-76f6bf54d6-tcqgb 1/1 Running 0 161m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/example-trino-cluster ClusterIP 10.96.25.35 8080/TCP 161m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/example-trino-cluster-coordinator 1/1 1 1 161m deployment.apps/example-trino-cluster-worker 2/2 2 2 161m NAME DESIRED CURRENT READY AGE replicaset.apps/example-trino-cluster-coordinator-bfb74c98d 1 1 1 161m replicaset.apps/example-trino-cluster-worker-76f6bf54d6 2 2 2 161m ``` -------------------------------- ### SHOW TABLES Example with LIKE clause Source: https://trino.io/docs/current/sql/show-tables.html Lists tables and views in the 'tiny' schema of the 'tpch' catalog that start with 'p'. ```sql SHOW TABLES FROM tpch.tiny LIKE 'p%' ``` -------------------------------- ### Catalog Configuration Example (JMX) Source: https://trino.io/docs/current/installation/deployment.html This example shows how to configure a catalog properties file to mount a connector. This specific example mounts the JMX connector as the 'jmx' catalog. ```properties connector.name=jmx ``` -------------------------------- ### Start Fluentbit with Configuration Source: https://trino.io/docs/current/admin/logging.html Command to start the fluentbit agent using the specified configuration file. ```bash fluent-bit -c config.yaml ``` -------------------------------- ### Start Kafka Server Source: https://trino.io/docs/current/connector/kafka-tutorial.html Starts the Kafka server using its properties file. This integrates Kafka with Trino. ```bash $ bin/kafka-server-start.sh config/server.properties [2013-04-22 15:01:47,028] INFO Verifying properties (kafka.utils.VerifiableProperties) [2013-04-22 15:01:47,051] INFO Property socket.send.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties) ... ``` -------------------------------- ### Configure Example HTTP Connector Source: https://trino.io/docs/current/release/release-0.54.html Mount the example-http connector as the 'example' catalog by creating an etc/catalog/example.properties file with the specified contents. ```properties connector.name=example-http metadata-uri=http://s3.amazonaws.com/presto-example/v1/example-metadata.json ``` -------------------------------- ### Example Invocations for to_one_hundred UDF Source: https://trino.io/docs/current/udf/sql/loop.html Example calls to the to_one_hundred SQL UDF, showing different starting values and step sizes, along with their expected return values. ```sql SELECT to_one_hundred(90, 1); --10 SELECT to_one_hundred(0, 5); --20 SELECT to_one_hundred(12, 3); -- 30 ``` -------------------------------- ### Drop Catalog Example Source: https://trino.io/docs/current/sql/drop-catalog.html Example of how to drop a catalog named 'example'. This command requires the catalog management type to be set to `dynamic`. ```sql DROP CATALOG example; ``` -------------------------------- ### Start Trino Server Source: https://trino.io/docs/current/connector/kafka-tutorial.html Command to start the Trino server after configuring the connector. ```bash $ bin/launcher start ``` -------------------------------- ### SQL UDF RETURN Examples Source: https://trino.io/docs/current/udf/sql/return.html Examples demonstrating how to return static values, expression results, and variable values from SQL UDFs. ```sql RETURN 42; RETURN 6 * 7; RETURN x; ``` -------------------------------- ### Example output of SHOW CREATE TABLE Source: https://trino.io/docs/current/sql/show-create-table.html This is an example of the output you might receive when running the SHOW CREATE TABLE command, illustrating the table's structure and configuration. ```sql Create Table ----------------------------------------- CREATE TABLE tpch.sf1.orders ( orderkey bigint, orderstatus varchar, totalprice double, orderdate varchar ) WITH ( format = 'ORC', partitioned_by = ARRAY['orderdate'] ) (1 row) ``` -------------------------------- ### Start ZooKeeper Server Source: https://trino.io/docs/current/connector/kafka-tutorial.html Starts the ZooKeeper server using its properties file. This is a prerequisite for running Kafka. ```bash $ bin/zookeeper-server-start.sh config/zookeeper.properties [2013-04-22 15:01:37,495] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig) ... ``` -------------------------------- ### JSON Path Examples Source: https://trino.io/docs/current/functions/json.html Examples of JSON path expressions, demonstrating 'strict' and 'lax' modes. ```sql 'strict $.price + $tax' ``` ```sql 'lax $[last].abs().floor()' ``` -------------------------------- ### Full MATCH_RECOGNIZE Example Source: https://trino.io/docs/current/sql/match-recognize.html Demonstrates a V-shape pattern detection on order prices over time for each customer. It partitions data by customer, orders by date, defines measures for starting, bottom, and top prices, and specifies how to handle matches and define pattern elements. ```sql SELECT * FROM orders MATCH_RECOGNIZE( PARTITION BY custkey ORDER BY orderdate MEASURES A.totalprice AS starting_price, LAST(B.totalprice) AS bottom_price, LAST(U.totalprice) AS top_price ONE ROW PER MATCH AFTER MATCH SKIP PAST LAST ROW PATTERN (A B+ C+ D+) SUBSET U = (C, D) DEFINE B AS totalprice < PREV(totalprice), C AS totalprice > PREV(totalprice) AND totalprice <= A.totalprice, D AS totalprice > PREV(totalprice) ) ``` -------------------------------- ### Start Trino and Prometheus Containers Source: https://trino.io/docs/current/admin/openmetrics.html Starts previously stopped Trino and Prometheus Docker containers. ```bash docker start trino docker start prometheus ``` -------------------------------- ### Table Data Example Source: https://trino.io/docs/current/functions/conditional.html Example data from the 'shipping' table, showing various fields including potentially problematic ones like 'origin_zip'. ```sql origin_state | origin_zip | packages | total_cost --------------+------------+----------+------------ California | 94131 | 25 | 100 California | P332a | 5 | 72 California | 94025 | 0 | 155 New Jersey | 08544 | 225 | 490 (4 rows) ``` -------------------------------- ### Example Distributed Query Plan Output Source: https://trino.io/docs/current/sql/explain.html This is an example output of the distributed query plan. It shows the different fragments, their layouts, partitioning, and operations. ```text Query Plan ------------------------------------------------------------------------------------------------------ Trino version: version Fragment 0 [SINGLE] Output layout: [regionkey, count] Output partitioning: SINGLE [] Output[regionkey, _col1] │ Layout: [regionkey:bigint, count:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} │ _col1 := count └─ RemoteSource[1] Layout: [regionkey:bigint, count:bigint] Fragment 1 [HASH] Output layout: [regionkey, count] Output partitioning: SINGLE [] Aggregate(FINAL)[regionkey] │ Layout: [regionkey:bigint, count:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} │ count := count("count_8") └─ LocalExchange[HASH][$hashvalue] ("regionkey") │ Layout: [regionkey:bigint, count_8:bigint, $hashvalue:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} └─ RemoteSource[2] Layout: [regionkey:bigint, count_8:bigint, $hashvalue_9:bigint] Fragment 2 [SOURCE] Output layout: [regionkey, count_8, $hashvalue_10] Output partitioning: HASH [regionkey][$hashvalue_10] Project[] │ Layout: [regionkey:bigint, count_8:bigint, $hashvalue_10:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} │ $hashvalue_10 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("regionkey"), 0)) └─ Aggregate(PARTIAL)[regionkey] │ Layout: [regionkey:bigint, count_8:bigint] │ count_8 := count(*) └─ TableScan[tpch:nation:sf0.01, grouped = false] Layout: [regionkey:bigint] Estimates: {rows: 25 (225B), cpu: 225, memory: 0B, network: 0B} regionkey := tpch:regionkey ``` -------------------------------- ### Example Distributed Plan JSON Output Source: https://trino.io/docs/current/sql/explain.html This is an example of the JSON output generated by the EXPLAIN (TYPE DISTRIBUTED, FORMAT JSON) command. It details the stages and data flow of a query plan. ```json { "0" : { "id" : "9", "name" : "Output", "descriptor" : { "columnNames" : "[regionkey, _col1]" }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count", "type" : "bigint" } ], "details" : [ "_col1 := count" ], "estimates" : [ { "outputRowCount" : "NaN", "outputSizeInBytes" : "NaN", "cpuCost" : "NaN", "memoryCost" : "NaN", "networkCost" : "NaN" } ], "children" : [ { "id" : "145", "name" : "RemoteSource", "descriptor" : { "sourceFragmentIds" : "[1]" }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count", "type" : "bigint" } ], "details" : [ ], "estimates" : [ ], "children" : [ ] } ] }, "1" : { "id" : "4", "name" : "Aggregate", "descriptor" : { "type" : "FINAL", "keys" : "[regionkey]", "hash" : "[]" }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count", "type" : "bigint" } ], "details" : [ "count := count(\"count_0\")" ], "estimates" : [ { "outputRowCount" : "NaN", "outputSizeInBytes" : "NaN", "cpuCost" : "NaN", "memoryCost" : "NaN", "networkCost" : "NaN" } ], "children" : [ { "id" : "194", "name" : "LocalExchange", "descriptor" : { "partitioning" : "SINGLE", "isReplicateNullsAndAny" : "", "hashColumn" : "[]", "arguments" : "[]" }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count_0", "type" : "bigint" } ], "details" : [ ], "estimates" : [ { "outputRowCount" : "NaN", "outputSizeInBytes" : "NaN", "cpuCost" : "NaN", "memoryCost" : "NaN", "networkCost" : "NaN" } ], "children" : [ { "id" : "227", "name" : "Project", "descriptor" : { }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count_0", "type" : "bigint" } ], "details" : [ ], "estimates" : [ { "outputRowCount" : "NaN", "outputSizeInBytes" : "NaN", "cpuCost" : "NaN", "memoryCost" : "NaN", "networkCost" : "NaN" } ], "children" : [ { "id" : "200", "name" : "RemoteSource", "descriptor" : { "sourceFragmentIds" : "[2]" }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count_0", "type" : "bigint" }, { "symbol" : \"$hashvalue\", "type" : "bigint" } ], "details" : [ ], "estimates" : [ ], "children" : [ ] } ] } ] } ] }, "2" : { "id" : "226", "name" : "Project", "descriptor" : { }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count_0", "type" : "bigint" }, { "symbol" : \"$hashvalue_1\", "type" : "bigint" } ], "details" : [ \"$hashvalue_1 := combine_hash(bigint '0', COALESCE(\"$operator$hash_code\"(\"regionkey\"), 0))\" ], "estimates" : [ { "outputRowCount" : "NaN", "outputSizeInBytes" : "NaN", "cpuCost" : "NaN", "memoryCost" : "NaN", "networkCost" : "NaN" } ], "children" : [ { "id" : "198", "name" : "Aggregate", "descriptor" : { "type" : "PARTIAL", "keys" : "[regionkey]", "hash" : "[]" }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" }, { "symbol" : "count_0", "type" : "bigint" } ], ``` -------------------------------- ### Create Catalog with PostgreSQL Connector and Environment Variables Source: https://trino.io/docs/current/sql/create-catalog.html Example of creating a catalog named 'example' using the PostgreSQL connector. It demonstrates setting connection details and using environment variables for sensitive information like user and password. ```sql CREATE CATALOG example USING postgresql WITH ( "connection-url" = 'jdbc:pg:localhost:5432', "connection-user" = '${ENV:POSTGRES_USER}', "connection-password" = '${ENV:POSTGRES_PASSWORD}', "case-insensitive-name-matching" = 'true' ); ``` -------------------------------- ### Column Definition for Ordinality Source: https://trino.io/docs/current/functions/json.html Example of defining a column to capture the row number (ordinality) of the extracted JSON data, starting from 1. ```sql row_num FOR ORDINALITY ``` -------------------------------- ### Bcrypt Password Format Source: https://trino.io/docs/current/security/password-file.html Example of a username and bcrypt-hashed password in the password file. Passwords must start with '$2y$' and use a minimum cost of 8. ```text test:$2y$10$BqTb8hScP5DfcpmHo5PeyugxHz5Ky/qf3wrpD7SNm8sWuA3VlGqsa ``` -------------------------------- ### UUID Type Example Source: https://trino.io/docs/current/language/types.html The UUID type represents a Universally Unique Identifier (UUID) or Globally Unique Identifier (GUID) as defined in RFC 4122. ```Trino SQL UUID '12151fd2-7586-11e9-8f9e-2a86e4085a59' ``` -------------------------------- ### Query System Connector Table Source: https://trino.io/docs/current/connector/system.html Retrieves all data from a specific table within the 'system' connector. This example shows how to query the 'nodes' table to get information about Trino cluster nodes. ```sql SELECT * FROM system.runtime.nodes; ``` -------------------------------- ### Accessing Unnamed ROW Fields by Position Source: https://trino.io/docs/current/language/types.html Unnamed or named row fields can be accessed by their position (starting at 1) using the subscript operator ([]). This example accesses the first field of a ROW. ```Trino SQL ROW(1, 2.0)[1] ``` -------------------------------- ### Example HTTP Connector Factory Creation Source: https://trino.io/docs/current/develop/example-http.html This snippet demonstrates how the ExampleConnectorFactory uses Guice to create and configure the ExampleConnector instance. It initializes the application with necessary modules and properties. ```java // A plugin is not required to use Guice; it is just very convenient Bootstrap app = new Bootstrap( new JsonModule(), new ExampleModule(catalogName)); Injector injector = app .doNotInitializeLogging() .setRequiredConfigurationProperties(requiredConfig) .initialize(); return injector.getInstance(ExampleConnector.class); ``` -------------------------------- ### OpenLDAP Group Provider Configuration Source: https://trino.io/docs/current/security/group-mapping.html Example configuration for an OpenLDAP group provider using search-based queries. This setup requires specifying base DNs for users and groups, along with search filters. ```properties group-provider.name=ldap group-provider.group-case=lower ldap.url=ldap://ldap.example.com:389 ldap.admin-user=cn=admin,dc=example,dc=com ldap.admin-password=your_password ldap.group-name-attribute=cn ldap.user-base-dn=ou=users,dc=example,dc=com ldap.user-search-filter=(uid={0}) ldap.use-group-filter=true ldap.group-base-dn=ou=groups,dc=example,dc=com ldap.group-search-filter=(cn=trino_*) ldap.group-search-member-attribute=member ``` -------------------------------- ### EXPLAIN output with cost estimates Source: https://trino.io/docs/current/optimizer/cost-in-explain.html This example demonstrates the output of an EXPLAIN statement, showing cost estimates for each plan node. The format includes rows, data size, CPU, memory, and network usage. ```text - Output[comment] => [[comment]] Estimates: {rows: 22 (1.69kB), cpu: 6148.25, memory: 0.00, network: 1734.25} - RemoteExchange[GATHER] => [[comment]] Estimates: {rows: 22 (1.69kB), cpu: 6148.25, memory: 0.00, network: 1734.25} - ScanFilterProject[table = tpch:nation:sf1.0, filterPredicate = ("nationkey" > BIGINT '3')] => [[comment]] Estimates: {rows: 25 (1.94kB), cpu: 2207.00, memory: 0.00, network: 0.00}/{rows: 22 (1.69kB), cpu: 4414.00, memory: 0.00, network: 0.00}/{rows: 22 (1.69kB), cpu: 6148.25, memory: 0.00, network: 0.00} nationkey := tpch:nationkey comment := tpch:comment ``` -------------------------------- ### Extract Substring from Start Source: https://trino.io/docs/current/functions/string.html Returns the rest of the string from a specified starting position. Supports negative start positions. ```sql SELECT substring('hello world', 7); ``` ```sql SELECT substring('hello world', -5); ``` -------------------------------- ### Equivalent PREPARE, EXECUTE, DEALLOCATE PREPARE Source: https://trino.io/docs/current/sql/execute-immediate.html This example shows the equivalent sequence of PREPARE, EXECUTE, and DEALLOCATE PREPARE statements for the parameterized query. ```sql PREPARE statement_name FROM SELECT name FROM nation WHERE regionkey = ? and nationkey < ? EXECUTE statement_name USING 1, 3 DEALLOCATE PREPARE statement_name ``` -------------------------------- ### Alluxio Client Configuration Example Source: https://trino.io/docs/current/object-storage/file-system-alluxio.html Example content for the `alluxio-site.properties` file, specifying Alluxio master hostname, port, and security authentication type. This file must be located in `/opt/alluxio/conf` on all Trino cluster nodes. ```properties alluxio.master.hostname=127.0.0.1 alluxio.master.port=19998 alluxio.security.authentication.type=NOSASL ``` -------------------------------- ### Start Trino as a Daemon Source: https://trino.io/docs/current/installation/deployment.html Use this command to start the Trino server in the background as a daemon process. The command returns the process ID of the started server. ```bash bin/launcher start ``` -------------------------------- ### Create Hive Table Source: https://trino.io/docs/current/connector/lakehouse.html Example of creating a Hive table with specified schema, format, partitioning, bucketing, and bucket count. Ensure the 'HIVE' type and 'ORC' format are supported and configured. ```sql CREATE TABLE hive_page_views ( view_time TIMESTAMP, user_id BIGINT, page_url VARCHAR, ds DATE, country VARCHAR ) WITH ( type = 'HIVE', format = 'ORC', partitioned_by = ARRAY['ds', 'country'], bucketed_by = ARRAY['user_id'], bucket_count = 50 ) ``` -------------------------------- ### Find the starting position of the nth pattern occurrence Source: https://trino.io/docs/current/functions/regexp.html Locates the starting index of a specific occurrence of a pattern within a string, optionally starting the search from a given position. ```sql SELECT regexp_position('I have 23 apples, 5 pears and 13 oranges', '\b\d+\b', 12, 1); -- 19 SELECT regexp_position('I have 23 apples, 5 pears and 13 oranges', '\b\d+\b', 12, 2); -- 31 SELECT regexp_position('I have 23 apples, 5 pears and 13 oranges', '\b\d+\b', 12, 3); -- -1 ``` -------------------------------- ### Set Default Catalog and Schema via URL Source: https://trino.io/docs/current/client/cli.html Start the CLI and set the default catalog and schema by including them in the Trino coordinator URL. ```bash ./trino http://trino.example.com:8080/tpch/tiny trino:tiny> SHOW TABLES; Table ---------- customer lineitem nation orders part partsupp region supplier (8 rows) ``` -------------------------------- ### PARTITION BY Clause Example Source: https://trino.io/docs/current/sql/match-recognize.html Illustrates how to partition input data for independent pattern matching. This ensures that pattern recognition is applied to each customer's orders separately. ```sql PARTITION BY custkey ``` -------------------------------- ### Basic START TRANSACTION Source: https://trino.io/docs/current/sql/start-transaction.html Starts a new transaction with default settings. ```sql START TRANSACTION; ``` -------------------------------- ### Prepare and Describe a Simple SELECT Statement Source: https://trino.io/docs/current/sql/describe-output.html Prepare a SELECT statement and then use DESCRIBE OUTPUT to view its four output columns. ```sql PREPARE my_select1 FROM SELECT * FROM nation; ``` ```sql DESCRIBE OUTPUT my_select1; ``` -------------------------------- ### Find the starting position of the first pattern occurrence from a specific start index Source: https://trino.io/docs/current/functions/regexp.html Finds the index of the first pattern occurrence, beginning the search from a specified starting position (inclusive). ```sql SELECT regexp_position('I have 23 apples, 5 pears and 13 oranges', '\b\d+\b', 5); -- 8 SELECT regexp_position('I have 23 apples, 5 pears and 13 oranges', '\b\d+\b', 12); -- 19 ``` -------------------------------- ### Example: Sampling with Joins Source: https://trino.io/docs/current/sql/select.html Shows how to apply different sampling methods (SYSTEM and BERNOULLI) to tables involved in a join operation. ```sql SELECT o.*, i.* FROM orders o TABLESAMPLE SYSTEM (10) JOIN lineitem i TABLESAMPLE BERNOULLI (40) ON o.orderkey = i.orderkey; ``` -------------------------------- ### START TRANSACTION with Isolation Level Source: https://trino.io/docs/current/sql/start-transaction.html Starts a new transaction and specifies the isolation level. ```sql START TRANSACTION ISOLATION LEVEL REPEATABLE READ; ``` -------------------------------- ### Show all functions in a specific schema Source: https://trino.io/docs/current/sql/show-functions.html Use this command to list all functions available in the 'default' schema of the 'example' catalog. This includes built-in, plugin, and user-defined functions. ```sql SHOW FUNCTIONS FROM example.default; ``` -------------------------------- ### START TRANSACTION with Read/Write Mode Source: https://trino.io/docs/current/sql/start-transaction.html Starts a new transaction and specifies whether it is read-only or read-write. ```sql START TRANSACTION READ WRITE; ``` -------------------------------- ### Prepare and Describe a CREATE TABLE Statement Source: https://trino.io/docs/current/sql/describe-output.html Prepare a CREATE TABLE AS SELECT statement and describe its output, which indicates the number of rows affected. ```sql PREPARE my_create FROM CREATE TABLE foo AS SELECT * FROM nation; ``` ```sql DESCRIBE OUTPUT my_create; ``` -------------------------------- ### Start Trino and Jaeger Containers Source: https://trino.io/docs/current/admin/opentelemetry.html Starts previously stopped Trino and Jaeger Docker containers. ```bash docker start jaeger docker start trino ``` -------------------------------- ### Example Download URL for PostgreSQL Plugin Source: https://trino.io/docs/current/installation/plugins.html Shows the URL structure for downloading a Trino plugin ZIP archive from GitHub releases, based on its Maven coordinates. ```text https://github.com/trinodb/trino/releases/download/481/trino-postgresql-481.zip ``` -------------------------------- ### Configure SingleStore Connector Source: https://trino.io/docs/current/connector/singlestore.html Create a catalog properties file to mount the SingleStore connector. Replace connection properties with your specific setup details. ```properties connector.name=singlestore connection-url=jdbc:singlestore://example.net:3306 connection-user=root connection-password=secret ``` -------------------------------- ### START TRANSACTION with Multiple Modes Source: https://trino.io/docs/current/sql/start-transaction.html Starts a new transaction and specifies both isolation level and read/write mode. ```sql START TRANSACTION ISOLATION LEVEL READ COMMITTED, READ ONLY; ``` ```sql START TRANSACTION READ WRITE, ISOLATION LEVEL SERIALIZABLE; ``` -------------------------------- ### Explain Table with USE Statement Source: https://trino.io/docs/current/connector/iceberg.html Demonstrates table redirection by explaining a table after setting the current schema. The output shows the actual catalog handling the query. ```sql USE example.example_schema; EXPLAIN SELECT * FROM example_table; ``` ```text Query Plan ------------------------------------------------------------------------- Fragment 0 [SOURCE] ... Output[columnNames = [...]] │ ... └─ TableScan[table = another_catalog:example_schema:example_table] ... ``` -------------------------------- ### Example System Access Control Configuration Source: https://trino.io/docs/current/develop/system-access-control.html This configuration file sets the name of the custom access control implementation and passes implementation-specific properties. ```properties access-control.name=custom-access-control custom-property1=custom-value1 custom-property2=custom-value2 ``` -------------------------------- ### Run Trino Container with Custom Configuration Source: https://trino.io/docs/current/installation/containers.html Starts a Trino container, mapping a local 'etc' directory to '/etc/trino' inside the container to use custom configuration files. ```bash $ docker run --name trino -d -p 8080:8080 --volume $PWD/etc:/etc/trino trinodb/trino ``` -------------------------------- ### Example Logical Plan Output Source: https://trino.io/docs/current/sql/explain.html An example of the text-formatted logical execution plan output for a Trino query. ```text Query Plan ----------------------------------------------------------------------------------------------------------------- Trino version: version Output[regionkey, _col1] │ Layout: [regionkey:bigint, count:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} │ _col1 := count └─ RemoteExchange[GATHER] │ Layout: [regionkey:bigint, count:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} └─ Aggregate(FINAL)[regionkey] │ Layout: [regionkey:bigint, count:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} │ count := count("count_8") └─ LocalExchange[HASH][$hashvalue] ("regionkey") │ Layout: [regionkey:bigint, count_8:bigint, $hashvalue:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} └─ RemoteExchange[REPARTITION][$hashvalue_9] │ Layout: [regionkey:bigint, count_8:bigint, $hashvalue_9:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} └─ Project[] │ Layout: [regionkey:bigint, count_8:bigint, $hashvalue_10:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: ?} │ $hashvalue_10 := "combine_hash"(bigint '0', COALESCE("$operator$hash_code"("regionkey"), 0)) └─ Aggregate(PARTIAL)[regionkey] │ Layout: [regionkey:bigint, count_8:bigint] │ count_8 := count(*) └─ TableScan[tpch:nation:sf0.01] Layout: [regionkey:bigint] Estimates: {rows: 25 (225B), cpu: 225, memory: 0B, network: 0B} regionkey := tpch:regionkey ``` -------------------------------- ### Check Docker Version Source: https://trino.io/docs/current/installation/kubernetes.html Verify if Docker is installed on your system. If this command fails, Docker needs to be installed. ```bash docker --version ``` -------------------------------- ### Extract Substring with Length Source: https://trino.io/docs/current/functions/string.html Returns a substring of a specified length from a starting position. Supports negative start positions. ```sql SELECT substring('hello world', 7, 5); ``` ```sql SELECT substring('hello world', -5, 3); ``` -------------------------------- ### Find First Substring Position Source: https://trino.io/docs/current/functions/string.html Returns the starting position of the first occurrence of a substring. Positions start at 1. ```sql SELECT strpos('hello world', 'world'); ``` -------------------------------- ### Show Create View Syntax Source: https://trino.io/docs/current/sql/show-create-view.html Displays the SQL statement that creates the specified view. Use this to inspect the definition of an existing view. ```sql SHOW CREATE VIEW view_name ``` -------------------------------- ### Get Type of Integer Source: https://trino.io/docs/current/functions/conversion.html Shows how to get the data type name of an integer literal using the typeof() function. ```sql SELECT typeof(123); -- integer ``` -------------------------------- ### Distributed EXPLAIN Plan (JSON Format) Source: https://trino.io/docs/current/sql/explain.html Shows a sample JSON output from the EXPLAIN command, detailing a query plan with table scans and estimated costs. ```json { "id" : "root", "name" : "Exchange", "type" : "DISTRIBUTED", "distributed" : { "stageId" : "0", "type" : "REPARTITION", "inputs" : [ { "id" : "0", "name" : "TableScan", "descriptor" : { "table" : "tpch:tiny:nation" }, "outputs" : [ { "symbol" : "regionkey", "type" : "bigint" } ], "details" : [ "regionkey := tpch:regionkey" ], "estimates" : [ { "outputRowCount" : 25.0, "outputSizeInBytes" : 225.0, "cpuCost" : 225.0, "memoryCost" : 0.0, "networkCost" : 0.0 } ], "children" : [ ] } ] } } ``` -------------------------------- ### Example Logical Plan Output (JSON) Source: https://trino.io/docs/current/sql/explain.html This is an example of the JSON output generated by EXPLAIN (TYPE LOGICAL, FORMAT JSON). It details the query plan structure, including nodes, outputs, and estimates. ```json { "id": "9", "name": "Output", "descriptor": { "columnNames": "[regionkey, _col1]" }, "outputs": [ { "symbol": "regionkey", "type": "bigint" }, { "symbol": "count", "type": "bigint" } ], "details": [ "_col1 := count" ], "estimates": [ { "outputRowCount": "NaN", "outputSizeInBytes": "NaN", "cpuCost": "NaN", "memoryCost": "NaN", "networkCost": "NaN" } ], "children": [ { "id": "145", "name": "RemoteExchange", "descriptor": { "type": "GATHER", "isReplicateNullsAndAny": "", "hashColumn": "" }, "outputs": [ { "symbol": "regionkey", "type": "bigint" }, { "symbol": "count", "type": "bigint" } ], "details": [ ], "estimates": [ { "outputRowCount": "NaN", "outputSizeInBytes": "NaN", "cpuCost": "NaN", "memoryCost": "NaN", "networkCost": "NaN" } ], "children": [ { "id": "4", "name": "Aggregate", "descriptor": { "type": "FINAL", "keys": "[regionkey]", "hash": "" }, "outputs": [ { "symbol": "regionkey", "type": "bigint" }, { "symbol": "count", "type": "bigint" } ], "details": [ "count := count(\"count_0\")" ], "estimates": [ { "outputRowCount": "NaN", "outputSizeInBytes": "NaN", "cpuCost": "NaN", "memoryCost": "NaN", "networkCost": "NaN" } ], "children": [ { "id": "194", "name": "LocalExchange", "descriptor": { "partitioning": "HASH", "isReplicateNullsAndAny": "", "hashColumn": "[$hashvalue]", "arguments": "[\"regionkey\"]" }, "outputs": [ { "symbol": "regionkey", "type": "bigint" }, { "symbol": "count_0", "type": "bigint" }, { "symbol": "$hashvalue", "type": "bigint" } ], "details":[], "estimates": [ { "outputRowCount": "NaN", "outputSizeInBytes": "NaN", "cpuCost": "NaN", "memoryCost": "NaN", "networkCost": "NaN" } ], "children": [ { "id": "200", "name": "RemoteExchange", "descriptor": { "type": "REPARTITION", "isReplicateNullsAndAny": "", "hashColumn": "[$hashvalue_1]" }, "outputs": [ { "symbol": "regionkey", "type": "bigint" }, { "symbol": "count_0", "type": "bigint" }, { "symbol": "$hashvalue_1", "type": "bigint" } ], "details":[], "estimates": [ ``` -------------------------------- ### SQL UDF Example with BEGIN Source: https://trino.io/docs/current/udf/sql/begin.html Example of a SQL UDF that uses the BEGIN statement to declare variables and compute a value. ```sql FUNCTION meaning_of_life() RETURNS integer BEGIN DECLARE a integer DEFAULT 6; DECLARE b integer DEFAULT 7; RETURN a * b; END ``` -------------------------------- ### Download and Make Twistr Executable Source: https://trino.io/docs/current/connector/kafka-tutorial.html Download the twistr tool and set execute permissions. This is the first step to setting up a live Twitter feed into Kafka. ```bash $ curl -o twistr https://repo1.maven.org/maven2/de/softwareforge/twistr_kafka_0811/1.2/twistr_kafka_0811-1.2.sh $ chmod 755 twistr ``` -------------------------------- ### Drop Role Example Source: https://trino.io/docs/current/sql/drop-role.html This example demonstrates how to drop a role named 'admin'. Ensure you have the necessary privileges to perform this operation. ```sql DROP ROLE admin; ``` -------------------------------- ### JSON Path Examples Source: https://trino.io/docs/current/functions/json.html Examples of JSON path expressions used with the json_query function, demonstrating 'strict' and 'lax' modes. ```sql 'strict $.keyvalue()?(@.name == $cust_id)' ``` ```sql 'lax $[5 to last]' ``` -------------------------------- ### Generate Query Plan with Input/Output Details Source: https://trino.io/docs/current/sql/explain.html Use EXPLAIN (TYPE IO, FORMAT JSON) to process a query and generate a plan detailing input and output information for accessed objects in JSON format. ```sql EXPLAIN (TYPE IO, FORMAT JSON) INSERT INTO test_lineitem SELECT * FROM lineitem WHERE shipdate = '2020-02-01' AND quantity > 10; ``` ```json Query Plan ----------------------------------- { inputTableColumnInfos: [ { table: { catalog: "hive", schemaTable: { schema: "tpch", table: "test_orders" } }, columnConstraints: [ { columnName: "orderkey", type: "bigint", domain: { nullsAllowed: false, ranges: [ { low: { value: "1", bound: "EXACTLY" }, high: { value: "1", bound: "EXACTLY" } }, { low: { value: "2", bound: "EXACTLY" }, high: { value: "2", bound: "EXACTLY" } } ] } }, { columnName: "processing", type: "boolean", domain: { nullsAllowed: false, ranges: [ { low: { value: "false", bound: "EXACTLY" }, high: { value: "false", bound: "EXACTLY" } } ] } }, { columnName: "custkey", type: "bigint", domain: { nullsAllowed: false, ranges: [ { low: { bound: "ABOVE" }, high: { value: "10", bound: "EXACTLY" } } ] } } ], estimate: { outputRowCount: 2, outputSizeInBytes: 40, cpuCost: 40, maxMemory: 0, networkCost: 0 } } ], outputTable: { catalog: "hive", schemaTable: { schema: "tpch", table: "test_orders" } }, estimate: { outputRowCount: "NaN", outputSizeInBytes: "NaN", cpuCost: "NaN", maxMemory: "NaN", networkCost: "NaN" } } ``` -------------------------------- ### Configure Default Function Catalog, Schema, and Path Source: https://trino.io/docs/current/admin/properties-sql-environment.html This example demonstrates how to configure the default catalog and schema for User-defined functions (UDFs) storage and set the `sql.path` property accordingly. This ensures that UDFs are stored in the specified catalog and schema, and that Trino can locate them. ```properties sql.default-function-catalog=brain sql.default-function-schema=default sql.path=brain.default ``` -------------------------------- ### Example Query for Aggregation Pushdown Source: https://trino.io/docs/current/admin/properties-optimizer.html Illustrates a query where aggregation is pushed below an outer join. This is an example of how the `optimizer.push-aggregation-through-outer-join` setting can be beneficial. ```sql SELECT * FROM item i WHERE i.i_current_price > ( SELECT AVG(j.i_current_price) FROM item j WHERE i.i_category = j.i_category); ``` -------------------------------- ### Example EXPLAIN statement Source: https://trino.io/docs/current/optimizer/cost-in-explain.html This snippet shows a basic EXPLAIN statement used to inspect query plan costs. ```sql EXPLAIN SELECT comment FROM tpch.sf1.nation WHERE nationkey > 3; ``` -------------------------------- ### Minimal Python UDF Example: doubleup Source: https://trino.io/docs/current/udf/python.html A minimal example demonstrating how to declare and use an inline Python UDF named 'doubleup'. This UDF takes an integer and returns its value multiplied by two. The example also shows how to invoke the UDF and the expected output. ```sql WITH FUNCTION doubleup(x integer) RETURNS integer LANGUAGE PYTHON WITH (handler = 'twice') AS $$ def twice(a): return a * 2 $$ SELECT doubleup(21); -- 42 ```