Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
55
Other Decks in Education
See All in Education
Human Perception and Cognition - Lecture 4 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.2k
Introduction - Lecture 1 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
2.5k
HCI and Interaction Design - Lecture 2 - Human-Computer Interaction (1023841ANR)
signer
PRO
0
1.3k
授業レポート:共感と協調のリーダーシップ(2025年上期)
jibunal
0
120
GOVERNOR ADDRESS:2025年9月29日合同公式訪問例会:2720 Japan O.K. ロータリーEクラブ、2025年10月6日卓話:藤田 千克由 氏(国際ロータリー第2720地区 2025-2026年度 ガバナー・大分中央ロータリークラブ・大分トキハタクシー(株)顧問)
2720japanoke
0
570
みんなのコード 2024年度活動報告書/ 2025年度活動計画書
codeforeveryone
0
340
RSJ2025 ランチョンセミナー 一歩ずつ世界へ:学生・若手研究者のための等身大の国際化の始め方
t_inamura
0
310
仏教の源流からの奈良県中南和_奈良まほろば館‗飛鳥・藤原DAO/asuka-fujiwara_Saraswati
tkimura12
0
140
Sanapilvet opetuksessa
matleenalaakso
0
33k
Entrepreneurship minor course at HSE 2025
karlov
0
100
ROSConJP 2025 発表スライド
f0reacharr
0
240
AI for Learning
fonylew
0
190
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
The Cult of Friendly URLs
andyhume
79
6.6k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
Embracing the Ebb and Flow
colly
88
4.8k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.6k
Writing Fast Ruby
sferik
629
62k
Visualization
eitanlees
149
16k
How STYLIGHT went responsive
nonsquared
100
5.8k
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