Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
OctoLab Cookbook: how to generate a unique key ...
Search
Kamil Samigullin
May 03, 2016
Education
1
39
OctoLab Cookbook: how to generate a unique key for a sequence
PHP tips and tricks: work with IteratorAggregate, Generator, SplQueue and SplDoublyLinkedList.
Kamil Samigullin
May 03, 2016
Tweet
Share
More Decks by Kamil Samigullin
See All by Kamil Samigullin
OctoLab Cookbook: Go lang tips and tricks - protection of sensitive config data
kamilsk
1
140
OctoLab Cookbook: how to use composer.yml and stop creating issues about
kamilsk
1
58
Enter Cookbook: refactoring under a microscope
kamilsk
1
57
Other Decks in Education
See All in Education
仏教の源流からの奈良県中南和_奈良まほろば館‗飛鳥・藤原DAO/asuka-fujiwara_Saraswati
tkimura12
0
160
バケットポリシーの記述を誤りマネコンからS3バケットを操作できなくなりそうになった話
amarelo_n24
1
140
DIP_1_Introduction
hachama
0
330
Linguaxes de programación
irocho
0
490
JavaScript - Lecture 6 - Web Technologies (1019888BNR)
signer
PRO
0
3.1k
Web Architectures - Lecture 2 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
子どものためのプログラミング道場『CoderDojo』〜法人提携例〜 / Partnership with CoderDojo Japan
coderdojojapan
PRO
4
17k
AIを使って最新研究 について調べて発表しよ う!
mickey_kubo
4
170
CSS3 and Responsive Web Design - Lecture 5 - Web Technologies (1019888BNR)
signer
PRO
1
3k
Node-REDで広がるプログラミング教育の可能性
ueponx
1
200
卒論の書き方 / Happy Writing
kaityo256
PRO
50
26k
Design Guidelines and Models - Lecture 5 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.2k
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
Site-Speed That Sticks
csswizardry
13
990
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The World Runs on Bad Software
bkeepers
PRO
72
12k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
390
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
How GitHub (no longer) Works
holman
316
140k
The Cult of Friendly URLs
andyhume
79
6.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Navigating Team Friction
lara
191
16k
Designing for Performance
lara
610
69k
Transcript
Episode #1.0.2 (2016-05-22) Level: Intermediate OctoLab Cookbook How to generate
a unique key for a sequence
The context
timestamp payment currency 18.03.2016 09:22:23 100 USD 18.03.2016 09:21:02 50
EUR 18.03.2016 09:19:46 10 USD 08.03.2016 09:31:03 10 USD 07.03.2016 22:52:17 145 USD 18.02.2016 23:17:25 35 EUR Import CSV from tinkoff.ru to TCA application
The problem
Merging timestamp payment currency 18.03.2016 09:22:23 100 USD 18.03.2016 09:21:02
50 EUR 18.03.2016 09:19:46 10 USD timestamp payment currency 18.03.2016 09:19:46 10 USD 08.03.2016 09:31:03 10 USD 07.03.2016 22:52:17 145 USD 18.02.2016 23:17:25 35 EUR timestamp payment currency 18.02.2016 23:17:25 35 EUR 17.02.2016 19:49:59 11 USD 02.02.2016 17:58:36 9 USD a first imported CSV file a second imported CSV file a third imported CSV file
The solution
- first iteration: simple, unique key constraint $table->addUniqueIndex([‘timestamp’, ‘payment’, ‘currency’]);
timestamp payment currency 22.02.2016 20:36:33 15 USD 22.02.2016 19:25:14 25
USD 22.02.2016 00:00:00 0,1 USD 22.02.2016 00:00:00 0,1 USD 21.02.2016 21:19:38 10 USD 21.02.2016 17:04:00 10 USD valid internal operations look exactly the same
- second iteration: buffering and forward hashing $table->addColumn(‘f_hash’, ‘string’, …)
$table->addUniqueIndex([‘f_hash’]);
None
column forward hash row 1 08bb542ead91978a26317a4aa8caf1e5d355706e row 2 e993895c5fd4fcbb22f9af9c7d341c47db87a8a7 row
3 7bb25dfeeaec0235cc5cdc4643a09e753687bded row 4 NULL buffer size = 2 column forward hash row 1 bd74be8fda860811368dfc3dd170f34652c73dea row 2 eaf057a4aac69217b5cc2c996679e7d1e11f411d row 3 NULL row 4 NULL buffer size = 3
- third iteration: bidirectional hashing $table->addColumn(‘b_hash’, ‘string’, …) $table->addUniqueIndex([‘b_hash’]);
None
column forward hash backward hash row 1 … NULL row
2 … 0b48e15756c28dc8a00d54594a1c25cabe707973 row 3 … af8d00a06f6e58ec06a650433df597cf4140d78b row 4 NULL 219fe3369d071daadedf81fde031e0f1e74f571b buffer size = 2 not-nullable combination
Limitations • number of rows in a CSV file must
be greater than or equal to the buffer size Benefits • import CSV files in any order • natural flow of the code with minimal changes in the original iteration
• StringifierInterface and CsvRowStringifier • BufferInterface and HashedBuffer • BufferedIterator
• changes in the original iteration The real-world example
Thank you for your attention! Have questions? Kamil Samigullin a
some developer
[email protected]
@ikamilsk github.com/kamilsk linkedin.com/in/kamilsk