ติดตั้ง 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

ตัวอย่างติดตั้ง 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

List Packages

> pip list

Python Virtual Environments

ติดตั้ง virtualenv

$ pip install virtualenv

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

$ 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

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