Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
edb-korea
WarehousePG-Tip
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
WarehousePG-Tip
/
14-0.PLPython Example
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
45 lines (37 loc) · 1.42 KB
main
Breadcrumbs
WarehousePG-Tip
/
14-0.PLPython Example
Copy path
Top
File metadata and controls
Code
Blame
45 lines (37 loc) · 1.42 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
-- 1. PL/Python Numpy histogram 함수
-- 온도 데이터 테이블 생성
CREATE TABLE public.sensor_readings (
sensor_id INT,
temperature REAL
);
-- 정규분포를 따르는 샘플 데이터 삽입
INSERT INTO public.sensor_readings
SELECT 1, (random() * 10 + 20)::REAL FROM generate_series(1, 1000); -- 평균 25도 근처의 데이터
-- PL/Python 확장 활성화 (최초 1회)
CREATE EXTENSION IF NOT EXISTS plpython3u;
-- Numpy 패키지 설치 (Greenplum 각 세그먼트 호스트에서 실행 필요)
-- pip install numpy
-- 히스토그램 결과를 저장할 타입 생성
CREATE TYPE histogram_result AS (
bin_edges REAL[],
counts BIGINT[]
);
CREATE OR REPLACE FUNCTION calculate_histogram(
data REAL[]
)
RETURNS histogram_result
AS $$
# plpy 모듈과 numpy 라이브러리를 임포트합니다.
import numpy as np
# Numpy의 histogram 함수를 호출합니다.
# bins=10은 데이터를 10개의 구간으로 나누겠다는 의미입니다.
counts, bin_edges = np.histogram(data, bins=10)
# 결과를 생성한 사용자 정의 타입에 맞춰 딕셔너리 형태로 반환합니다.
# Numpy 배열을 Python 리스트로 변환해야 Greenplum 배열 타입과 호환됩니다.
return {
"counts": list(counts),
"bin_edges": list(bin_edges)
}
$$ LANGUAGE plpython3u;
SELECT (calculate_histogram(ARRAY_AGG(temperature))).*
FROM public.sensor_readings;
You can’t perform that action at this time.