Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
619 views
in Technique[技术] by (71.8m points)

kql - Kusto Query to update table column type with out impacting data

I have a kusto table with id:int and name:string fields with data in it. I am trying to alter table schema types for id: int to id:long. I tried the below but it throws the below error. I also tried .alter instead of .alter-merge but no luck. What is the procedure to update Kusto table column type for existing table with data and without disturbing the current data?

.alter-merge table mytable
(Id: long, Name: string)

Error: 'Alter table does not support column data type change for existing columns (Id). Current type=I32, requested type=I64'.

question from:https://stackoverflow.com/questions/65915915/kusto-query-to-update-table-column-type-with-out-impacting-data

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's the process you should follow to achieve what you want:

  1. Create a new table named OldTable with the updated schema
  2. Create a function named Table (should be exact name as your original table) that will return union (OldTable | project id = tolong(id), name), (Table | project id = tolong(id), name) - this way, whenever someone writes Table, he'll call the function that will return data from both tables in the correct schema
  3. Swap Table and OldTable
  4. When the data in the OldTable table ages out (at the end of the retention period), it will become empty, and you'll have to first delete the Table function, then the OldTable table

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...