Skip to content

Instantly share code, notes, and snippets.

@depesz
Created November 16, 2021 16:19
Show Gist options
  • Save depesz/39096aef34b88e03bc83c829aed1f742 to your computer and use it in GitHub Desktop.
Save depesz/39096aef34b88e03bc83c829aed1f742 to your computer and use it in GitHub Desktop.
SHARD_REGEXP = %r{("?)(canvas|cluster\d+(?:_shard_\d+)?)\1\.}.freeze
query = 'select * from "cluster123_shard_3".xx join cluster123_shard_3.yy on a = b'
counts = Hash.new(0)
n_query = query.gsub(SHARD_REGEXP) do | s | counts[s]+=1; "SOME_SHARD."; end
# At the end counts is:
# {"\"cluster123_shard_3\"."=>1, "cluster123_shard_3."=>1}
# And I'd like it to be:
# {"cluster123_shard_3"=>2}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment