I wanted to load fixed width data with no row delimiter. I tried org.apache.hadoop.hive.contrib.serde2.RegexSerDe as below:
create external table tbl_temp
(
f1 string,
f2 string,
f3 string,
f4 string,
f5 string,
f6 string,
f7 string
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES ("input.regex" = "(.{3})(.{3})(.{2})(.{6})(.{1})(.{30})(.{5})")
LOCATION '/user/usrNm/dir1';
and the data is like
xxxyyyzzaaaaaabccccccc 11111xxxyyyzzaaaaaabccccccc 11111xxxyyyzzaaaaaabccccccc ccc
with no row delimiter.
When I do a select only 1 record is shown. Other data is ignored.
How to load a fixed width file with no row delimiter.
Thanks
Related
In VB .net I'm wanting to run an sqlite select statement to fetch only numeric values from a text field (a4) which contains both numbers and letters.
My sqlite text a4 field data contains data like this:
28 days
1966
the 100 years war
In would like to be able to fetch
28
1966
100
The sqlite a4 field has a text data type
This is what I have tried
SELECT a4 from data where CAST(a4 AS INTEGER) GLOB '[0-9]'
SELECT a4 FROM data WHERE a4 REGEXP '[0-9]'
I have search for an answer but only found MS SQL answer that uses ISNUMERIC which doesn't exist in SQLITE.
Thanks
You can do it in SQL for SQLite3:
SELECT ROUND(a4) from data WHERE NOT ROUND(a4) = 0;
This is because non-numeric values applied to the ROUND() function result in a value of 0. For example:
sqlite> select round('hello');
round('hello')
--------------
0.0
..whereas numeric values stored as text become numbers:
sqlite> select round('1234');
round('1234')
-------------
1234.0
N.B. There is a limitation to this solution is if a numeric value is also '0' or rounds to 0.0, such as text value '0.1'. It also will give a false positive if the text starts with a number but includes other characters, e.g.
sqlite> select round('1234Hello');
round('1234Hello')
------------------
1234.0
Not done in the database but in the client code.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim strings() As String = {"28 days", "1966", "the 100 years war"}
Dim numbers As New List(Of String)
For Each s In strings
Dim num As String = ""
For Each c As Char In s
If Char.IsNumber(c) Then
num &= c
End If
Next
numbers.Add(num)
Next
For Each num In numbers
Debug.Print(num)
Next
'28
'1966
'100
End Sub
I am very new into Phython and I have to create a script. I want to read an Excel worksheet thorough Phython and output the cells value in my customized format.
My input Excel is :
B Server1 NESLDS1 Local T Remote F Mltstdby F Group 60 Grpdef 60 Pad
B Server2 NESLDS2 Local T Remote F Mltstdby F Group 60 Grpdef 60 Pad
My question:
I am running one Phython code to get parameter's Value in each row, if it is string or integer, I want the value in quotes (""). Now if the value is Boolean i.e. T or F then I want the value without quotes.
My code :
import xlrd
loc = ("C:\parameter.xlsx")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
for k in range(2,sheet.nrows):
if sheet.cell_value(k,0)=="B":
print ('\n')
for i in range (2,14,2):
print('"%s"' % sheet.cell_value(k,i),",",end='',sep='')
My current output is:
"NESLDS2","T","F","F","60","60",
"NESLDS2","T","F","F","60","60",
What I want :
I want T and F without quotes.
What I'm starting with:
(Column 1)FileName.xml (Column 2)a very long LONG datatype string exists here.
What I need:
(Column 1) FileName.xml (Column 2)LONG characters up to 2K (Column 3) LONG characters up to 4k (Column 4) LONG Characters from 4k-8k (Column 5) LONG Characters from 8k-12k ... (so on and so forth)
Thanks in advance.
Assuming the long data is stored as CLOB datatype, YOu can make use of the package dbms_lob
dbms_lob.substr will meet your need.
e.g: dmbs_lob.sunstr(colname,2000,1) will give you first 2K character.
Here param1 = column_name, param2 = No. of characters, param3 = offset
Dim InputString() As String
Dim i As Integer
InputString = Split(InputName, " ")
For i = 0 To UBound(InputString)
CurrentDb.Execute "INSERT INTO InventoryInputT(InputID) VALUES ('" & InputString(i) & "')"
Next i
Thus, an entry of
data1 data2 data3
In the textbox of the form resulted in a table input of
record1 data1
record2 data2
record3 data3
Which is desired. The scanner we purchased uses either a 'tab' delimiter or a 'return'... it can also use 'add jump line' but I don't know what that means and it seems to be similar to return (on the surface)
Is there any way I can alter my code to either:
1) use the tab function
- the issue here is if the data in the scanner is represented as: 'data1 [tab] data2 [tab] data3'
and then I upload that to the textbox, access seems to read the data as:
-input 'data1'
-execute [tab] (which means it navigates out of my textbox to whatever the next button is)
... because it has navigated out of the textbox it can no longer enter 'data2' in the textbox... as such I don't know if this can be solved
2) Can I use the return setup as it allows each data entry to have its own unique line in the textbox
- can I adjust my code so it sets each line of the textbox to a value of i and then runs through my execute code? Example:
data entered (as displayed in textbox)
data1
data2
data3
Get code to read it as:
data1 = line1 = i=0 - execute to table
data2 = line2 = i=1 - execute to table
data3 = line3 = i=2 - execute to table
or something along those lines?
The second parameter of the Split() function is called Delimiter. This can be set to a single space, multiple spaces (as in your example) or even a tab character (vbTab in VBA). It's very flexible.
I have a column with filenames of the following format:
somenumber_sometext_1_100_AA
These filenames are in column A. I need to scan each filename in each cell and copy the number 1 and paste it into column B and copy the number 100 and paste it in column C, all of the same row as the filename. I then want to repeat for the next cell down in column A.
Help would be appreciated!
As this was tagged with VBA, I will give a simple vba macro solution.
The easiest way is to define a VBA function called splitText(test,delim, n) , which will split text by a delimiter, and get the nth column. This is so commonly needed, I wish they'd just make it standard.
Function splitText(txt As String, delim As String, n As Integer)
splitText = split(txt, delim)(n)
End Function
Then, if the string is A1, put this in B1:
=splitText(A1,"_",2)
And this in C1:
=splitText(A1,"_",3)
With:
3141543_junktext_4563_10098_ZZ
in cell A1, in B1 enter:
=TRIM(MID(SUBSTITUTE($A1,"_",REPT(" ",999)),COLUMNS($A:C)*999-998,999))
and in C1 enter:
=TRIM(MID(SUBSTITUTE($A1,"_",REPT(" ",999)),COLUMNS($A:D)*999-998,999))
To display 4563 and 10098
If each section is delimited (ie in the example by _) then Text to Columns with that as the delimiter and then deleting the last and the first two columns may be convenient.
(But copy into a new column first or you will lose your source data.)