Algorithm: Course Schedule
Review: Gradual Database Migration
Tips: Load File through Stage into Snowflake Table
Share: Some Thoughts about Being a Mentor
Algorithm - Course Schedule
Key points: if there's a cycle return False
, else return True
Depth First Search
class Solution:
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
def dfs(node, adj, visit, in_stack):
if in_stack[node]:
return True
if visit[node]:
return False
visit[node] = True
in_stack[node] = True
for next_node in adj[node]:
if dfs(next_node, adj, visit, in_stack):
return True
in_stack[node] = False
return False
adj = [[] for _ in range(numCourses)]
for target, base in prerequisites:
adj[target].append(base)
visit = [False for _ in range(numCourses)]
in_stack = [False for _ in range(numCourses)]
for i in range(numCourses):
if dfs(i, adj, visit, in_stack):
return False
return True
Kahn's Algorithm
For a vertex, the number of head ends adjacent to a vertex is called the indegree of the vertex and the number of tail ends adjacent to a vertex is its outdegree.
class Solution:
def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
from collections import deque
indegree = [0 for _ in range(numCourses)]
adj = [[] for _ in range(numCourses)]
for target, base in prerequisites:
adj[base].append(target)
indegree[target] += 1
queue = deque()
for i in range(numCourses):
if indegree[i] == 0:
queue.append(i)
num_visit = 0
while queue:
node = queue.popleft()
num_visit +=1
for next_node in adj[node]:
indegree[next_node] -= 1
if indegree[next_node] == 0:
queue.append(next_node)
return num_visit == numCourses
Review - Gradual Database Migration
In order to migrate the huge database safely. Start from writing both old and new columns from application.
P.S. This is just part of the origin tech blog from Kraken Technology.
I think it’s easier to explain the method by diving into an example. For example, how to migrate from a contact_info
column to two columns, email
and phone
Add new columns(Nullable)
Deploy schema change
Update application logic to write to both old and new columns
Deploy application change
Backfill existing data. Use a migrate scrip to populate the new columns for existing customers.
Verify data integrity. Confirm all data in new columns are legal.
Make new column required.
Remove the old logic from application
Deploy code change
Drop old column
Ref
Tips - Load File through Stage into Snowflake Table
TL;DR It’s possible to query non-existing columns from file, and Snowflake would treat it as
NULL
value
There is a csv data file.
# data file
"header1"|"header2"|"header3"
"a"|"b"|"c"
There is a Snowflake table
test
.
"header1"|"header2"|"header3"|"header4"
"a" |"b" |"c" |"d"
Query
COPY INTO test FROM (
SELECT $1, $2, $3, $4 FROM @S3_STAGE/file
)
Even though there’s no
col4
in data file, when running this query Snowflake engine would fill withNULL
. Hence, if the column is not nullable, it would raise error.
Share - Some Thoughts about Being a Mentor
Across my 5-year development experience, I recently find that I prefer to be an engineer who could properly guide and mentor people than simply tackling technical issues. In order to extend the possibility, I have discussed with my manager, and it comes with the following points:
How to earn trust?
I believe stable communication like weekly 1:1 conversation is always necessary.
I used to think that the more I speak I lose more trust. At the end, I regard it as overthinking. Trust begins when people feel truly heard but it shouldn’t stop us from showing what we don’t know or failure.
It’s necessary to be consistenly reliable. If we promise to send a resource or make an introduction, do it right now otherwise we forget about it. Trust erodes quickly when people can’t count on us.
Recognize the communication style of our mentees.
Some people are willing to talk, and some people feel too shy to speak. We need to adjust our way to approach them. For example, compare to pure oral communication, it would be helpful if we add the written communication section in a 1:1 conversation. For those who are more proactive, starting with some small talks would be helpful.
We don’t always have topics for weekly conversation. In order to prevent the embarrasement, we could decide the framework for discussion. For example:
one thing that we learned
one thing that is worried
one thing that is good
Give structural feedback
Sometimes, instead of giving direct feedback, it’s more appropriate to express the idea to his/her direct manager. Currently I haven’t met this case yet if it happens I am definitely willing to share it.
Learn to manage
I haven’t start this chapter yet. So! Let’s see~
Recommendation
The Making of a Manager by Julie Zhuo, which is similar to The Manager’s Path but I regard it as a summary of it.
The Manager’s Path: A Guide for Tech Leaders Navigating Growth and Change | Fournier, Camille | Software Development, which covers the content from being a manager to being a CTO. Not only managment but also how to do as a member, a mentor, and a tech lead.
Become an Effective Software Engineering Manager: How to Be the Leader Your Development Team Needs, which focuses on management.
Thank your for reading my self-learning post!! I hope you enjoy this post, and I need your small favor to help me improve the post!! And feel free to comment!