从给定的输入生成最高数字并使用 hive 将 0 替换为 9
有人可以帮助/建议我应该如何处理配置单元中的以下情况。
我有一列包含一些值,其中一些数字后有 0(6 位数字后),我需要将所有这些 0 替换为 9。如果我在 5 位数字后有 0,那么我需要在开头包含 0,然后再次需要替换 6 位数字后面的 0。PFB 一些样本记录和预期输出。
Input output
1234560000000 1234569999999
123450000000 0123459999999
12340000000 0012349999999
1230000000 0001239999999
所以这里基本上我需要从右到左检查。 1234560000000 在这里,我将从右(0)开始检查,一旦找到任何数字,我将用 9 替换所有 0,如果除 0 之外的数字计数小于 6,则将在开头添加 0。
请建议
Can Someone Help/suggest me how should I handle below scenario in hive.
I have one column which contain some values in which I have 0's after some digits(after 6 digits) I need to replace all these 0 by 9. and if i have 0's after 5 digits then i need to include 0 at the starting and then again need to replace 0's which comes after 6 digits.PFB some sample records and expected output.
Input output
1234560000000 1234569999999
123450000000 0123459999999
12340000000 0012349999999
1230000000 0001239999999
so here basically I need to check from right to left.ie. 1234560000000
here I will start checking from right (0) and as soon as find any digit i will replace all the 0's by 9 and if digit count other then 0 is less than 6 then will add 0 in the beginning.
kindly suggest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将字符串拆分为两部分:末尾的数字和其他所有内容,用 9 替换零,连接。
演示:
结果
Split string on two parts: digits at the end and everything else, replace zeroes with 9, concatenate.
Demo:
Result
我从未使用过 hive,但它看起来具有我在其他数据库中使用的所有功能,
我们如何将所有 0 替换为空格,然后将空格去掉right 和
rpad
用 '9' 达到原始长度,然后lpad
用 '0' 最多 13,然后替换
任何空格(在中间,例如如果我们要转换101010000 到 000101019999) 返回“0”如前所述,从未使用过 hive,因此这里可能需要解决一些小语法问题 - 如果 hive 没有通过自动将数字转换为字符串来提供数字的长度,例如,你需要插入一些东西来进行显式转换。您也可以对数字进行 log10。
我不知道有任何小提琴网站提供蜂巢作为测试器。
I've never used hive but it looks to have all the functions I would use in some other DB
How about we
replace
all the 0 to spaces,rtrim
the spaces off the right andrpad
with '9' out to the original length, thenlpad
up to 13 with '0' and thenreplace
any spaces (in the middle, eg if we are converting 101010000 to 000101019999) back to '0'As noted, never used hive so there might be some minor syntax things to resolve here - if hive doesn't give you the length of a number by auto converting it to a string, for example, you'll need to stick something in for doing an explicit convert. You could alternatively do the log10 of the number.
I don't know of any fiddle sites that offer hive as a tester..