Some built-in functions cannot run on some columns because they are built on numerical or character columns. We will not be able to determine the data type of a column just by looking at it. In columns of numbers or dates, string data types may be used. A numeric column may or may not indicate whether it is TinyInt, SmallInt, Int, or BigInt. In order to know the column’s data type there is a built-in function named TYPEOF available in Apache Impala.
Let’s see how it can be used.
SELECT TYPEOF(StudentID), TYPEOF(StudentName) FROM StudentMarks LIMIT 1;
This returns INT and STRING for the specified columns.
SELECT TYPEOF(date1) FROM DateTest;
This returned TIMESTAMP.
SELECT TYPEOF(100), TYPEOF(100000), TYPEOF(100000000000000), TYPEOF(12.29);
This returned the following:
+——————+———————–+—————————————+———————+
| typeof(100) | typeof(100000) | typeof(100000000000000) | typeof(12.29) |
+——————+———————–+—————————————+———————+
| TINYINT | INT | BIGINT | DECIMAL(4,2) |
+——————+————————+————————————–+———————+
Please note that it will not work if the column is assigned to a complex data type.
Hope you find this article helpful.
Please subscribe to receive notifications on latest posts.
2 comments