Why split('TEST','') returns two extra elements:- ["","T","E","S","T",""] - hive

Why is the Hive split function returning two extra elements? My input string only has 4 characters but split returns an array with 6 elements.
hive> select split('TEST','');
OK
["","T","E","S","T",""]
My goal was to convert the input string to character array.

Related

Hivesql question: im trying to format 'datatype: double' to chars of 9 strings but add 0s to leading string if not upto 9 string

I am trying to remove space or special characters and format 'datatype: double' to chars of 9 strings but add 0s to leading string if not upto 9 string. Each row output have diff amount of strings
Row Record
922,421
1,294,043
22,513,01
24,655
My expectation:
000922421
001294043
002251301
000024655
What i tried: cast(cast(column_name as format '9(9)') as chars(9)). It throws error
Use lpad.
But first remove comma with blank using replace() and then lpad() 9 places with0s.
select lpad(replace( '922,421',',',''),9,'0') as col

How to add a character to the last third place of a string?

I have a column with numbers with various lengths such as 50055, 1055,155 etc. How can I add a decimal before the last 2nd place of each so that it would be 500.55, 10.55, and 1.55?
I tried using replace by finding the last 2 numbers and replace it with .||last 2 number. That doesn't always work because of a possibility of multiple repetition of the same sequence in the same string.
replace(round(v_num/2),substr(round(v_num/2),-2),'.'||substr(round(v_num/2),-2))
You would divide by 100:
select v_num / 100
You can convert this into a string, if you want.

Convert float64 to a string with thousand separators

I have a Population Estimate series with numbers as float64 and I need to convert them to a string with thousands separator (using commas). Using all significant digits (no rounding).
e.g. 12345678.90345 -> 12,345,678.90345
Try applying a comma-float string formatter.
population = population.apply('{:,.5f}'.format)
To achieve the desired formatting, you could use '{:,}'.format.
This will use commas as thousands separator and only output the values that are in your data and not clip or fill to a certain number of digits.
data = data.apply('{:,}'.format)

Python: Remove exponential in Strings

I have been trying to remove the exponential in a string for the longest time to no avail.
The column involves strings with alphabets in it and also long numbers of more than 24 digits. I tried converting the column to string with .astype(str) but it just reads the line as "1.234123E+23". An example of the table is
A
345223423dd234324
1.234123E+23
how do i get the table to show the full string of digits in pandas?
b = "1.234123E+23"
str(int(float(b)))
output is '123412299999999992791040'
no idea how to do it in pandas with mixed data type in column

How to get the last number of a string using selenium webdriver

1 - 2 of 2
Above is my text. This is from paging of a web application. How do i extract the last number of the above text. SO i will get the count of list in that page and i can run a loop with respect to the number.
You can use substring
Let's consider your example. You have a String 1 - 2 of 2 (pagination probably)
Each of individual character is a specified index of a String
1 = 0
space = 1
- = 2
space = 3
etc.
String has a set of methods to perform various tasks. One of them is length() which gives you number of characters in your String
What you can do is to pass your length of String to substring.
Example:
myString.substring(0,1) will give you results of 1
myString.substring(0,myString.length()) wil give you results of 1 - 2 of 5
Additional info: myString.length() is an int type so you can perform math operations like + or -
myString.substring(0,myString.length()-1) will give you results of 1 - 2 of
I gave you the tools, now it's time for you to find the solutions.
You could just split the string using the spaces and then grab the last element of the split array. That should cover you even if the last number has more than one digit. Throw in a trim, just in case, to remove any leading/trailing white space.
String[] splitter = pageCount.trim().split(" ");
System.out.println(splitter[splitter.length - 1]);