\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{pdendek} \pdfinfo{ /Title (apache-pig-2-czesc.pdf) /Creator (Cheatography) /Author (pdendek) /Subject (Apache Pig - 2. czesc Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Apache Pig - 2. czesc Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{pdendek} via \textcolor{DarkBackground}{\uline{cheatography.com/19160/cs/2219/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}pdendek \\ \uline{cheatography.com/pdendek} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 12th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{4.32 cm} x{3.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Projekcje, przeksztalcenia}} \tn % Row 0 \SetRowColor{LightBackground} Zapis z tabeli A do tabeli B kolumn col1 i col2 & B = foreach A generate col1, col2; \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Zapis z tabeli A do tabeli B kolumn col1 i col2 (odniesienie po numerze kolumny) & B = foreach A generate \$0,\$1; \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} Zapis z tabeli A do tabeli B kolumn od col1 do col2 (odniesienie po numerze kolumny) & B = foreach A generate \$0..\$1; \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} Zapis z tabeli A do tabeli B kolumn do col2 (odniesienie po numerze kolumny) & B = foreach A generate ..\$1; \tn % Row Count 15 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{A = load 'input.tsv' as (col1:chararray, col2:long, col3:int); \newline B = ...} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.48 cm} x{3.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Ograniczanie liczby wierszy}} \tn % Row 0 \SetRowColor{LightBackground} Próbka 50\% z tabeli A & B = sample A 0.5; \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} 10 wierszy z tabeli A & B = limit A 10; \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Filtrowanie wierszy}} \tn % Row 0 \SetRowColor{LightBackground} Odfiltrowanie wierszy z wartościami większymi niż zadana & B = filter A by year\textgreater{}2000; \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} j.w., rozbudowany przykład & B = filter A by (year \textgreater{} 2000 and year \textless{} 2010); \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Odfiltrowanie wierszy z wartościami niepustymi & B = filter A by description is not null; \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} Odfiltrowanie wierszy z tekstami spełniającymi zadane wyrażenie regularne & B = filter A by text MATCHES '.{\emph{Miami.}}'; \tn % Row Count 13 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.8 cm} x{3.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Operacje masowe}} \tn % Row 0 \SetRowColor{LightBackground} Grupowanie wierszy mających tę samą wartość kolumny col1 & B = group A by col1; \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Grupowanie wierszy mających te same wartości kolumn col1 i col2 & B = group A by (col1,col2); \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} Grupowanie wszystkich wierszy & B = group A all; \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} Sortowanie wierszy rosnąco wg. wartości kolumny col1 & B = sort A by col1 asc; \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} Sortowanie wierszy malejąco wg. wartości kolumny col1 & B = sort A by col1 desc; \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} Rankingowanie wierszy rosnąco wg. wartości col1 & B = rank A by col1 asc; \tn % Row Count 17 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.584 cm} x{2.508 cm} x{2.508 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Operacje na kolumnach zawierajacych tekst}} \tn % Row 0 \SetRowColor{LightBackground} Podzial tekstu na słowa & B = foreach A generate id, \seqsplit{TOKENIZE(txt)} as tokens; & bag:\{(chararray)\} \seqsplit{TOKENIZE(chararray)} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Podział tekstu na określoną liczbę fragmentów względem znaku podziału & B = foreach A generate id, STRSPLIT(txt,',',2) as tup; & tuple \seqsplit{STRSPLIT(chararray},chararray,int) \tn % Row Count 10 (+ 6) % Row 2 \SetRowColor{LightBackground} Usunięcie wiodących i kończących białych znaków & B = foreach A generate TRIM(txt) as txt; & chararray \seqsplit{TRIM(chararray)} \tn % Row Count 15 (+ 5) % Row 3 \SetRowColor{white} \seqsplit{Wyciągnięcie} tekstu \seqsplit{spełniającego} zadane wyrażenie regularne & B = foreach A generate \seqsplit{REGEX\_EXTRACT(txt},'({[}0-9{]}+)',1) as txt; & chararray \seqsplit{REGEX\_EXTRACT(chararray}, regex, group num) \tn % Row Count 20 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{Operacje przekształcające kolumny tekstowe} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{PB1}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Splaszczanie kolekcji}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{B = group A by col1; \newline -{}- B:\{group,A:\{(col1)\}\} \newline C = foreach B generate group, flatten(A); \newline -{}- C:\{group, col1\} \newline \newline D = foreach B generate A as bag1, A as bag2; \newline E = foreach D generate FLATTEN(bag1) as t1, FLATTEN(bag1) as t2; \newline -{}- E:\{t1,t2\} \newline -{}- wiersze w tabeli E reprezentują wszystkie możliwe pary obiektów z bag1 oraz bag2 (produkt kartezjański)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Operacja na grupach wierszy z kolumnami liczbowymi}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A = load 'input.tsv' as (id1:long,val:long); \newline B = group A all; \newline \newline -{}- wartość średnia, maksymalna, minimalna dla kolumny val \newline C = foreach B generate AVG(A.val); \newline D = foreach B generate MAX(A.val); \newline E = foreach B generate MIN(A.val); \newline \newline -{}- liczba wierszy w tabeli A. \newline -{}- wszystkie wiersze z tabeli A zostały umieszczone w jednym bag-u o nazwie A umieszczonym w wierszu w tabeli B. \newline -{}- Wynik zliczenia elementów z bag-a zostanie umieszczony w tabeli C \newline C = foreach B generate COUNT(A) as cnt;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Makra}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{DEFINE COUNTALL(intable) RETURNS out\{ \newline grpd = group \$intable all; \newline \$out = foreach grpd generate COUNT(\$intable); \newline \} \newline \newline A = load ... \newline B = COUNTALL(A);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Pig umożliwia zdefiniowanie części kodu jako makra \newline i odwoływanie się do niego przez nazwę} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Import skryptow z makrami}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import 'macros.pig'; \newline \newline A = load ... \newline B = \seqsplit{MACRO\_FROM\_OTHER\_FILE(A);}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Pig umożliwia zaimportowanie do skryptu Pigowego innych skryptów Pigowych, \newline które np. zawierają makra. \newline Skrypty importowane NIE MOGĄ ZAWIERAĆ operacji REGISTER.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}