ติดตั้ง Pentaho

เข้าหน้าดาว์นโหลด Pentaho from Hitachi Vantara download | SourceForge.net แล้วเลือก Download

จะได้ไฟล์ pdi-ce-9.2.0.0-290.zip ประมาณ 1.74 GB

ดาว์นโหลดคู่มือ

Set Environment Variables (System variables)

PENTAHO_JAVA
C:\Program Files\Java\jre1.8.0_321\bin\java.exe

PENTAHO_JAVA_HOME
C:\Program Files\Java\jre1.8.0_321

JAVA_HOME
C:\Program Files\Java\jdk1.8.0_291

รันไฟล์ pdi-ce-9.2.0.0-290\data-integration\Spoon.bat

วาด Transform ง่ายๆ ด้วย Table output Mapping

เชื่อมต่อ MS SQL Server

ถ้าเชื่อมต่อ MS SQL Server แล้ว error ว่า

Driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver' could not be found, make sure the 'MS SQL Server (Native)' driver (jar file) is installed.
com.microsoft.sqlserver.jdbc.SQLServerDriver

ให้ทำตามนี้ Connect Pentaho to MS SQL Server (Native) – Stack Overflow

  • Download Microsoft JDBC Drivers 4.2 on 
    https://www.microsoft.com/en-us/download/details.aspx?id=11774
  • Unzip the package in a temp directory
  • Close Spoon
  • Copy ‘<temp directory>\sqljdbc_6.0.8112.200_enu\sqljdbc_6.0\enu\auth\x64\sqljdbc_auth.dll‘ to ‘C:\Program Files\Java\jre1.8.0_321\bin
  • Copy ‘<temp directory>\sqljdbc_6.0.8112.200_enu\sqljdbc_6.0\enu\jre8\sqljdbc42.jar‘ to ‘<Kettle installation folder>\data-integration\lib
  • Open Spoon
  • Test connection in spoon
  • Delete temp directory

Python PIP

Check if PIP is Installed

python -m pip --version
pip --version

update pip

pip install --upgrade pip

upgrade package

pip install --upgrade  <package-name>

ตัวอย่างติดตั้ง package camelcase

pip install camelcase

การใช้ Package camelcase · PyPI

import camelcase

c = camelcase.CamelCase()
txt = "hello world"

print(c.hump(txt))           # Hello World
from camelcase import CamelCase
c = CamelCase()
s = 'this is a sentence that needs CamelCasing!'
print (c.hump(s))
# This is a Sentence That Needs CamelCasing!

*ดูจาก output เหมือนจะเป็น PascalCase ?

Find Packages

PyPI · The Python Package Index

Remove a Package

> pip uninstall camelcase

Listing Packages #

> pip list

To list outdated packages, and show the latest version available:

> pip list --outdated
Package    Version Latest Type
---------- ------- ------ -----
Jinja2     3.1.2   3.1.3  wheel
Markdown   3.5.1   3.5.2  wheel
setuptools 65.5.0  69.0.3 wheel

To show details about an installed package:

> python -m pip show Jinja2
Name: Jinja2
Version: 3.1.2
Summary: A very fast and expressive template engine.
Home-page: https://palletsprojects.com/p/jinja/
Author: Armin Ronacher
Author-email: armin.ronacher@active-4.com
License: BSD-3-Clause
Location: c:\project\github3\mkdocs\.venv\lib\site-packages
Requires: MarkupSafe
Required-by: mkdocs, mkdocs-material

Python Virtual Environments

ติดตั้ง virtualenv

> python -m pip install virtualenv 
> python -m pip list
Package      Version
------------ -------
distlib      0.3.7
filelock     3.13.1
pip          23.3.1
platformdirs 3.11.0
virtualenv   20.24.6

สร้างไดเร็กทอรี

$ mkdir python-virtual-environments 
$ cd python-virtual-environments

Create a new virtual environment inside the directory ชื่อ env

# Python 2
$ virtualenv env

# or

# Python 3
$ python3 -m venv env

activate scripts บน linux

$ source env/bin/activate
(env) $

activate scripts บน Windows

> .\env\scripts\activate
(env) >

ถ้าเจอ Error ตามนี้

+ .\env\scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

ให้แก้ไขด้วยการเปิด PowerShell แบบ “Run as Administrator” (How to enable execution of PowerShell scripts? – Super User) แล้วพิมพ์คำสั่ง

set-executionpolicy remotesigned

การออกจาก virtual environments ให้พิมพ์คำสั่ง

$ deactivate

ตัวอย่างการ setup Flask

สร้างไฟล์ requirements.txt

Flask==2.0.2

สร้างไฟล์ app.pyQuickstart — Flask Documentation (2.3.x) (palletsprojects.com)

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, World!</p>"

พิมพ์คำสั่งตามนี้ (บน Windows)

> python -m venv .venv
> .\.venv\Scripts\activate

> pip install -r requirements.txt
> flask run

เปิด browser ไปที่ http://127.0.0.1:5000/

Python Variables

Creating Variables

x = 5                # int
y = "John"           # str
z = True             # bool

Case-Sensitive

x = 5
X = 10.0
print(x == X)        # False

Casting

str(obj) แปลงเป็นสตริง
int(s) แปลงเป็นเลขจำนวนเต็ม
float(s)
แปลงเป็นเลขทศนิยม

x = str(3)           # x will be str
y = int(3)           # y will be int
z = float(3)         # z will be float
x = int(1)           # x will be 1
y = int(2.8)         # y will be 2
z = int("3")         # z will be 3
x = float(1)         # x will be 1.0
y = float(2.8)       # y will be 2.8
z = float("3.5")     # z will be 3.5

hex(i) แปลงเป็นเลขฐานสิบหก
oct(i) แปลงเป็นเลขฐานแปด

x = hex(16)          # x will be str 0x10
y = oct(8)           # y will be str 0o10

ord(c) แปลงอักขระเป็นรหัสแอสกี้

x = ord('A')         # x will be int 65