How can I check the database of a table? - hadoop

I have a table name SOME_TABLE but I don't know the databse it belongs to.
How do I check it?
I suppose, it's impossible to do it from Hive level, cause you need to select database first...
Pawel

Query the metastore directly
Demo
Hive
create table SOME_TABLE (i int);
Metastore (MySQL)
use metastore;
select d.name
from TBLS as t
join DBS as d
on d.DB_ID =
t.DB_ID
where t.TBL_NAME = 'some_table'
;
+----------+
| name |
+----------+
| local_db |
+----------+

You can use the Hive command SHOW DATABASES; to list all databases and then use the SHOW TABLES IN database_name LIKE 'table_name'; command to to see if the table exist in the database.

Related

CTE (With table as) in sql server equivalent in hive?

I use WITH table_name AS (select...;) command in SQL Developer to create temporary table and use that temp table in following queries. What is the similar command in Hadoop Hive?
Using SQL assistant User interface on Hadoop Hive.
I tried the following example, which gives error-
Create table Failed,80:
CREATE TEMPORARY TABLE temp1(col1 string);
CREATE TEMPORARY TABLE temp2 AS Select * from table_name;
Maybe you must write case sensitive like this:
CREATE TEMPORARY TABLE temp1(col1 STRING);
The same CTE as in MySQL:
with your_table as (
select 'some value' --from etc etc
)
select * from your_table;
Another example: https://stackoverflow.com/a/54960324/2700344
Hive CTE Official docs

Viewing tables in CockroachDB

How can I find out which tables I have in CockroachDB? I tried looking for my schema and couldn't find that, so I'm not sure how to find out which tables I've already created or what their columns are.
First, you'll need to find your databases (which are CockroachDB's equivalent to PostgreSQL's schemas) using either:
MySQL-style SHOW DATABASES statement
PostgreSQL-style by querying information_schema.schemata. For example:
SELECT schema_name FROM information_schema.schemata;
Once you have the database name, you can find the tables using either:
MySQL-style SHOW TABLES statement
PostgreSQL-style by querying information_schema.tables. For example:
SELECT table_name FROM information_schema.tables WHERE table_schema = '[database to check]';
Once you find the tables, you can get more information about them using SHOW COLUMNS FROM [table] or the information_schema database.

Impala can perform a COUNT(*) but not a SELECT * from a table

I came across a bizarre Impala behaviour. I've create a table in HUE from a .csv file I've copied into the Hadoop cluster. I can correctly navigate the table in HUE via the Metastore Manager but I can't run the following query in Impala, as it throws an IllegalStateException: null exception:
select *
from my_db.my_table
limit 100;
The strange thing is that the following command retrieve the correct number of rows:
select
count(*)
from my_db.my_table;
The error is caused by invalid types. Not all hive data types are supported in impala. Impala has a timestamp and no date type. When your table has date type it will show as invalid_type in impala when described and impala cannot select this data type. For solution try changing the column to timestamp
Describe <table name>;
| invalid_type | |
| invalid_type | |
I'm getting the exact same issue. I changed the query to select each column from the table individually (i.e. select col1, col2, col3...etc.) and found that Impala didn't like a date datatype column. Changing it to timestamp fixed the issue and I can now do a select * from the table.

Grant create external table in Sentry

I have a 4 node cloudera cluster with kerberos enabled on it with sentry securing Hive service.
When i am create a table using hive user i am able to do so as it have all privileges on database default.
0: jdbc:hive2://clnode4:10000/default> create table t123 (a int);
No rows affected (0.204 seconds)
0: jdbc:hive2://clnode4:10000/default> show tables from default;
+--------------+--+
| tab_name |
+--------------+--+
| t1 |
| t12 |
| t123 |
+--------------+--+
3 rows selected (0.392 seconds)
But when i am trying to create a external table on same env with same user hive i am getting error as below
0: jdbc:hive2://clnode4:10000/default> create external table t1_ex (a string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LOCATION 'hdfs:///user/olap/KyvosDemo/Distance.csv';
Error: Error while compiling statement: FAILED: SemanticException No valid privileges
User hive does not have privileges for CREATETABLE (state=42000,code=40000)
I have provided all access on URI as well from were i am reading the data for external table.
Is there any way to provide create external table to user in sentry any help would be great.
I am able to solve the problem by granting all privileges on the server to hive user as below
grant all on server server1 to role hive;
role hive is assigned to hive user.
Edit
More help on this one can find the server name in hive configuration with the property name "hive.sentry.server"

How to have the list of table in a monetdb database?

In postgresql, one can have all tables names by running the following query
SELECT table_name FROM information_schema.tables WHERE table_schema='public';
Is there something similar in monetdb to have the list of tables ?
I finally find this query
select tables.name from tables where tables.system=false ;
If you are using mclient, in the command line you could simply use the command "\d" to list all the tables in the current database.
sql> \d
TABLE sys.table1
TABLE sys.table2
TABLE sys.table3
Additionally, use the command "\d tablename" to view the metadata of a table - equivalent to "show create table" in mysql.

Resources