GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feldera/python/felderize/examples/api_usage.py at main · feldera/feldera

Expand file tree

/

api_usage.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
69 lines (56 loc) · 2.07 KB
/

api_usage.py

Copy path

File metadata and controls

69 lines (56 loc) · 2.07 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
"""Example: translate Spark SQL to Feldera SQL with the felderize Python API.
Run from `python/felderize/` with the project venv (so `felderize` is importable
and ANTHROPIC_API_KEY is available, e.g. from a .env file):
.venv/bin/python examples/api_usage.py
"""
from felderize import Config, Status, translate_spark_to_feldera
SCHEMA = """
CREATE TABLE orders (
id BIGINT,
region STRING,
status STRING,
amount DECIMAL(10, 2),
created_at TIMESTAMP
) USING parquet;
"""
QUERY = """
CREATE OR REPLACE TEMP VIEW revenue_by_region AS
SELECT
region,
date_trunc('MONTH', created_at) AS month,
SUM(amount) AS total
FROM orders
WHERE status = 'PAID'
GROUP BY region, date_trunc('MONTH', created_at);
"""
def main() -> None:
# Reads ANTHROPIC_API_KEY, FELDERIZE_MODEL, and (for validate=True)
# FELDERA_COMPILER from the environment / a .env file.
cfg = Config.from_env()
# validate=True compiles the output against the Feldera compiler and repairs
# it using the compiler's feedback. Set validate=False to skip the compiler
# (faster, but the output SQL is not verified).
result = translate_spark_to_feldera(SCHEMA, QUERY, cfg, validate=False)
print(f"status: {result.status.value}\n")
print("-- Schema --")
print(result.feldera_schema.strip())
print("\n-- Query --")
print(result.feldera_query.strip())
if result.unsupported:
print("\nunsupported:")
for item in result.unsupported:
print(f" - {item}")
if result.warnings:
print("\nwarnings:")
for warning in result.warnings:
print(f" - {warning}")
# Branch on status the way a real integration would.
if result.status is Status.SUCCESS:
print("\nOK — the translated SQL is ready to deploy to a Feldera pipeline.")
else:
# Status.UNSUPPORTED -> some constructs became CAST(NULL ...) placeholders;
# Status.ERROR -> best-effort SQL that did not compile.
print("\nReview needed — see the unsupported/warnings above.")
if __name__ == "__main__":
main()
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.