by shigemk2

当面は技術的なことしか書かない

Python unicodeな文字列でreplaceとかformatとかやったときの挙動

unicodeな文字列でreplaceとかformatとかやったときの挙動

>>> a = "日本語".decode("utf-8")
>>> a
u'\u65e5\u672c\u8a9e'
>>> b = "{}".format(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

Python KeyError in format

ソースコードを追っかけても原因がよくわからなかったけどドキュメントを読んだらなんとなくわかった

>>> a = "{} {'alpha': 1234, 'omega': 5678}".format("test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: "'alpha'"
>>> a = "{} {{'alpha': 1234, 'omega': 5678}}".format("test")
>>> a
"test {'alpha': 1234, 'omega': 5678}"

Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.

https://docs.python.org/2/library/string.html#format-string-syntax

Presto row_number/rank/dense_rank

  • prestoにもrank/desne_rank/row_numberがある
    • row_number 機械的にidを割り振る
    • rank 重複値は同順位だが、次の順位は重複ぶんだけ飛ばす
    • dense_rank 重複値は同順位だが、次の順位は+1

クエリ。

WITH dataset AS
  ( SELECT *
   FROM (
         VALUES 10,
                100,
                500,
                500,
                1000,
                1500 ) AS t(num))
SELECT num,
       ROW_NUMBER() OVER( ORDER BY num) as row_number,
       RANK() OVER( ORDER BY num) as rank,
       DENSE_RANK() OVER( ORDER BY num) as dense_rank
FROM dataset;

結果。

NUM ROW_NUMBER RANK DENSE_RANK
10 1 1 1
100 2 2 2
500 3 3 3
500 4 3 3
1000 5 5 4
1500 6 6 5

6.15. Window Functions — Presto 0.202 Documentation

Data Sampling In Presto

http://itref.fc2web.com/oracle/function/row_number.html

Rundeck dupeOption

  • API経由でRundeckジョブを登録(インポート)するときのオプションで、URLパラメーターで制御(YAML/XMLの定義ファイルに書いても動かない)
  • ジョブ定義ファイルにジョブのuuidが書かれているとき
    • dupeOption=skip 登録しない
    • dupeOption=update 編集する
    • dupeOption=create 登録できない
  • ジョブ定義ファイルにジョブのuuidが書かれてないとき
    • dupeOption=skip 別ジョブ登録
    • dupeOption=update 別ジョブ登録
    • dupeOption=create 登録

うーむ

  • Rundeck 2.11.3-1

rundeck/test-jobs-v13.sh at master · rundeck/rundeck · GitHub