Query Syntax
Basic SELECT Queries
Query blockchain data using standard SQL syntax:Namespace and Table Syntax
Datasets in Amp use anamespace/dataset.table naming convention:
Namespaces with slashes or special characters must be enclosed in double quotes.
Common Query Patterns
Filtering by Block Range
Querying Logs and Events
Aggregations (Batch Queries Only)
Aggregate functions work in batch mode but are not supported in streaming queries:Window Functions (Batch Queries Only)
User-Defined Functions (UDFs)
Amp provides blockchain-specific UDFs for working with EVM data:Hex Encoding/Decoding
Unit Shifting (Token Decimals)
Convert between human-readable and raw token amounts:Event Topic Extraction
Available UDFs
evm_decode_hex - Convert hex strings to binary
evm_decode_hex - Convert hex strings to binary
Decodes hex strings (with or without
0x prefix) to FixedSizeBinary.evm_encode_hex - Convert binary to hex strings
evm_encode_hex - Convert binary to hex strings
Encodes
FixedSizeBinary(20) or FixedSizeBinary(32) to hex string.shift_units - Convert token decimals
shift_units - Convert token decimals
Shifts decimal point for token amount conversions.
evm_topic - Extract event topics by index
evm_topic - Extract event topics by index
Retrieves a specific topic from the topics array.
evm_decode_type - Decode EVM types
evm_decode_type - Decode EVM types
Decodes binary data according to Solidity ABI types.
evm_encode_type - Encode to EVM types
evm_encode_type - Encode to EVM types
Encodes values according to Solidity ABI types.
DataFusion SQL Support
Amp supports the full DataFusion SQL dialect, including:- SELECT - Projection, aliases, expressions
- FROM - Table references, subqueries
- WHERE - Filtering with complex predicates
- JOIN - INNER, LEFT, RIGHT, FULL, CROSS
- GROUP BY - Aggregations (batch only)
- ORDER BY - Sorting (batch only)
- LIMIT/OFFSET - Result pagination (batch only)
- DISTINCT - Deduplication (batch only)
- Window Functions - OVER clause (batch only)
- CTEs (WITH) - Common Table Expressions
- UNION/INTERSECT/EXCEPT - Set operations
- Subqueries - Nested SELECT statements
Data Types
DataFusion supports standard SQL types:- Numeric:
INT,BIGINT,DECIMAL,FLOAT,DOUBLE - String:
VARCHAR,TEXT - Binary:
BINARY,VARBINARY - Boolean:
BOOLEAN - Temporal:
DATE,TIMESTAMP,TIME - Complex:
ARRAY,STRUCT,MAP
Query Modes
Batch Queries (Default)
Execute once and return complete results:Streaming Queries
Continuously process new blocks as they arrive:Streaming queries require the Arrow Flight interface and have limitations on supported operations. See Streaming for details.
Examples by Use Case
Latest Blocks
Contract Event Analysis
Gas Usage Statistics (Batch Only)
Next Steps
Arrow Flight
Execute SQL queries via high-performance gRPC
JSON Lines
Query via simple HTTP interface
Streaming
Set up real-time streaming queries