명령줄 인터페이스
명령줄 인터페이스 (Command line interface)
Trino CLI는 쿼리를 실행하기 위한 터미널 기반의 대화형 셸이에요. CLI는 자체 실행(self-executing) JAR 파일이라 일반 UNIX 실행 파일처럼 동작해요.
출처: 문서
본문
CLI는 HTTP/HTTPS를 통한 클라이언트 프로토콜로 클러스터의 코디네이터와 통신해요.
요구사항 (Requirements)
Trino CLI에는 다음 요구사항이 있어요:
- PATH에 Java 11 이상이 있어야 해요. 압축 해제 성능 향상을 위해 Java 22 이상을 권장해요.
- Trino 클러스터의 코디네이터에 HTTP/HTTPS 네트워크 접근이 가능해야 해요.
- 스풀링 프로토콜이 활성화되어 있다면, 구성된 오브젝트 스토리지에 네트워크 접근이 가능해야 해요.
CLI 버전은 Trino 클러스터 버전과 같거나 더 새로운 것이어야 해요. 이전 버전은 보통 동작하지만 일부 하위 집합만 정기적으로 테스트돼요. 350 이전 버전은 지원되지 않아요.
설치 (Installation)
trino-cli-483을 다운로드해 trino로 이름을 바꾸고, chmod +x로 실행 권한을 준 뒤 실행해서 CLI 버전을 확인하세요:
./trino --version
또는 JAR로 직접 실행할 수도 있어요:
java -jar trino-cli-*-executable.jar --version
./trino를 실행해야 한다면, 파일 이름을 바꿨을 때 실행이 안 된다면 ./trino http://trino.example.com:8080처럼 바로 접속:
./trino http://trino.example.com:8080
CLI를 실행하면 프롬프트가 뜨는데, help로 지원 명령을 볼 수 있어요:
trino> help
Supported commands:
QUIT
EXIT
CLEAR
EXPLAIN [ ( option [, ...] ) ]
options: FORMAT { TEXT | GRAPHVIZ | JSON }
TYPE { LOGICAL | DISTRIBUTED | VALIDATE | IO }
DESCRIBE
SHOW COLUMNS FROM
SHOW FUNCTIONS
SHOW CATALOGS [LIKE ]
SHOW SCHEMAS [FROM ] [LIKE ]
SHOW TABLES [FROM ] [LIKE ]
USE [.]
쿼리 실행 예시:
trino> SELECT count(*) FROM tpch.tiny.nation;
_col0
-------
25
(1 row)
Query 20220324_213359_00007_w6hbk, FINISHED, 1 node
Splits: 13 total, 13 done (100.00%)
2.92 [25 rows, 0B] [8 rows/s, 0B/s]
URL에 카탈로그/스키마를 포함하면 프롬프트에 그 컨텍스트가 나타나요:
./trino http://trino.example.com:8080/tpch/tiny
trino:tiny> SHOW TABLES;
Table
----------
customer
lineitem
nation
orders
part
partsupp
region
supplier
(8 rows)
USE 명령으로도 컨텍스트를 바꿀 수 있어요:
trino> USE tpch.tiny;
USE
trino:tiny>
URL 파라미터로도 설정을 넘길 수 있어요:
./trino 'https://trino.example.com?SSL=true&SSLVerification=FULL&clientInfo=extra'
인증 (Authentication)
HTTPS를 통한 인증 연결 예시:
./trino https://trino.example.com
비밀번호 인증을 쓰려면 --password를 추가하고 사용자 이름을 지정해요:
./trino https://trino.example.com --user=exampleusername --password
비밀번호를 환경 변수로 설정해 대화형 프롬프트 없이 쓸 수도 있어요:
export TRINO_PASSWORD='LongSecurePassword123!@#'
./trino https://trino.example.com --user=exampleusername --password
Kerberos 인증 사용 예시:
#!/bin/bash
./trino \
--server https://trino.example.com \
--krb5-config-path /etc/krb5.conf \
--krb5-principal [email protected] \
--krb5-keytab-path /home/someuser/someuser.keytab \
--krb5-remote-service-name trino
Kerberos 디버깅을 위해선 다음 JVM 옵션을 쓸 수 있어요:
java \
-Dsun.security.krb5.debug=true \
-Djava.security.debug=gssloginconfig,configfile,configparser,logincontext \
-Dtrino.client.debugKerberos=true \
-jar trino-cli-*-executable.jar \
--server https://trino.example.com \
--krb5-config-path /etc/krb5.conf \
--krb5-principal [email protected] \
--krb5-keytab-path /home/someuser/someuser.keytab \
--krb5-remote-service-name trino
TRINO_CONFIG 환경 변수로 CLI 설정 파일을 지정해 여러 클러스터를 오갈 수 있어요:
TRINO_CONFIG=kerberos-cli.properties trino https://first-cluster.example.com:8443
TRINO_CONFIG=ldap-cli.properties trino https://second-cluster.example.com:8443
설정 파일 예시:
output-format-interactive=AUTO
timezone=Europe/Warsaw
user=trino-client
network-logging=BASIC
krb5-disable-remote-service-hostname-canonicalization=true
배치 실행 (Batch execution)
--execute로 단일 쿼리를 실행해서 출력을 만들 수 있어요:
trino --execute 'SELECT nationkey, name, regionkey FROM tpch.sf1.nation LIMIT 3'
기본 (CSV) 출력:
"0","ALGERIA","0"
"1","ARGENTINA","1"
"2","BRAZIL","1"
JSON 출력 예시:
{"nationkey":0,"name":"ALGERIA","regionkey":0}
{"nationkey":1,"name":"ARGENTINA","regionkey":1}
{"nationkey":2,"name":"BRAZIL","regionkey":1}
필드가 여러 개일 때의 출력 형식, 그리고 aligned 출력:
nationkey | name | regionkey
----------+-----------+----------
0 | ALGERIA | 0
1 | ARGENTINA | 1
2 | BRAZIL | 1
record 형식 출력:
-[ RECORD 1 ]--------
nationkey | 0
name | ALGERIA
regionkey | 0
-[ RECORD 2 ]--------
nationkey | 1
name | ARGENTINA
regionkey | 1
-[ RECORD 3 ]--------
nationkey | 2
name | BRAZIL
regionkey | 1
오류 진단 (Error diagnostics)
쿼리 오류는 실패한 SQL과 함께 표시돼요:
Query 20200707_170726_00030_2iup9 failed: line 1:25: Column 'region' cannot be resolved
SELECT nationkey, name, region FROM tpch.sf1.nation LIMIT 3
기본 출력:
$ trino
trino> select count(*) from tpch.tiny.nations;
Query 20200804_201646_00003_f5f6c failed: line 1:22: Table 'tpch.tiny.nations' does not exist
select count(*) from tpch.tiny.nations
--debug 플래그로 스택 트레이스를 포함한 상세 진단을 볼 수 있어요:
$ trino --debug
trino> select count(*) from tpch.tiny.nations;
Query 20200804_201629_00002_f5f6c failed: line 1:22: Table 'tpch.tiny.nations' does not exist
io.trino.spi.TrinoException: line 1:22: Table 'tpch.tiny.nations' does not exist
at io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:48)
at io.trino.sql.analyzer.SemanticExceptions.semanticException(SemanticExceptions.java:43)
...
at java.base/java.lang.Thread.run(Thread.java:834)
select count(*) from tpch.tiny.nations
더 알아보기 (Learn more)
다른 클라이언트 도구가 궁금하다면 JDBC 드라이버 문서를 이어서 읽어 보세요.