I’m very fresh with database and R. At the moment, I would like to connect R with database(Hive) and use R as the tool to query data from source.
The problem is that we have multiple databases, but I just wanna connect the specific database to work around. How to do that in R? For now, i’m using USE statement to select specific database but it is not working.
My script is
Library(“DBI”)
Library(“RODBC”)
Conn<- odbcConnect(dsn=“Mydsn”)
Query<- “USE MY_SPECIFIC_DATABASE
SELECT*FROM MY_TABLE”
Res<-sqlQuery(Conn, Query)
I know we can select by [database].[table]. But I really appreciated if you have another way to solve this problem.
Also I cannot edit info in DSN cause no permission.
Please give me some advises to deal with this issue. Thank you
Related
Looking through the influxdb website, documentation doesn't seem to
cover some functionality that typical db commands would. Does
anyone know how to move to a new name or outright rename a database inside of
influxdb?
Does anyone have a recommendation which R package to use with
influxdb?
Is there a way to load influx with -precision rfc3339 (human
readable timestamping) automatically set within the configuration?
Currently renaming databases is not supported in influxDB. Discussion is going on in influxDB's github repo on the feature's need and complexity.
https://github.com/influxdata/influxdb/issues/4154
The feature was implemented and then reverted due to bugs
Renaming is only possible by copying data into a new database:
SELECT * INTO "copy_NOAA_water_database"."autogen".:MEASUREMENT FROM "NOAA_water_database"."autogen"./.*/ GROUP BY *
Documentation: https://archive.docs.influxdata.com/influxdb/v1.2//query_language/data_exploration/#example-1-rename-a-database
The GROUP BY * clause is important as it preserves the tags.
I have not tried it for myself. But there are some answers in this link https://github.com/influxdata/influxdb.com/issues/384
ALTER DATABASE <db> RENAME TO <new_db>
I used this blog post as a basis for creating my SQLite tables.
Using the SQL Server Compact/SQLite Toolbox, I can view the created tables nicely.
However, in order to first create the connection in that tool, I had to locate the SQLite database I had created. I did a hard drive search for it, and found it in:
C:\Users\Clay\AppData\Local\Packages\99129e92-ebeb-4800-a0e5-
d0e43b016009_qtyjefqf75sa6\LocalState\photrax.sqlite
Now how in the world would I know that it was in 99129e92-ebeb-4800-a0e5-
d0e43b016009_qtyjefqf75sa6 (there are many similar Welch-looking folder names beneath C:\Users\Clay\AppData\Local\Packages, so how would I know which one it's in)?
Surely there's a more elegant way to find it than doing a global search.
C:\Users\Clay\AppData\Local\Package is where all your apps store their data and 99129e92-ebeb-4800-a0e5-
d0e43b016009 is most likely your package ID from the appx manifest. You can just use ApplicationData.LocalFolder.Path to get the path.
I'm working on some R-scripts which require the use of database queries. My IT department mentioned to me that these scripts require too much of the database (shared pool) and I should use bind-variables.
I am not very familiar with database designing, but I found out that bind variables are like variables i.e. if you use for example and date=:var in a statement.
Is it possible to use such statements when working with R (RODBC)?
Thank u very much
It seems that using bind variables is a part of the SQL query you write. So I presume that when you connect to the Oracle database using RODBC, you can pass an valid SQL query that contains bind variable syntax, and that this would simply work.
I created a database mdf file a while back and created a diagram of foreign keys. Lately, I needed to add several tables and there was an error saying I couldn't do the diagram because I'm not the owner.
So, I didn't update the diagram but added the tables anyway. My app seems to be working fine with the new tables. I'm using linq-to-sql and the design surface of the ORM doesn't show the connection between the new and the old tables.
My question is this: if the app works both with and without the diagram, what's the benefit of creating one? I know I can read an 800-page book and get the answer but I was wondering what the 2-3 line answer would be.
Thanks.
Diagram is just modeling tool.. no need to use it, but cool to visualise db, easier to write queries if you're not creator of db.
You can switch owner of db in options at "File" tab.
I want a tool through which I can get the respective hive query by giving the PL/SQL query. There are lots of tools available which convert sql to hql. ie: taod for cloude database. But it does not show me the respective hive query.
Is there any such kind of tool whose convert given sql to hql. Please help me.
Thanks and Regards,
Ratan
Please take a look at open-source project PL/HQL at http://www.hplsql.org/ which is now a part of Hive 2.x or higher version. It allows you to run existing SQL Server, Oracle, Teradata, MySQL etc. stored procedures in Hive.
Ratan, I did not how to start responding. So, lets start like this. I think you checked toad and thinking like there is a tool to convert SQL to hive QL. I do not think there is such a tool.
Let me clarify like this, HIVE QL, is same as SQL. Check this links before you are trying to write some queries:
https://cwiki.apache.org/confluence/display/Hive/LanguageManual,
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF.
This is simple to understand if you know sql and simple to write (as you check the HIve ql).
Hive doesnot have many operators the sql supports. For example:
select * from sales where country like 'EU~%'; "HIVE SUPPORTS LIKE"
But try this negative queries as we write in SQL :
select * from sales where country not like 'EU~%'; "HIVE DOES NOT SUPPORT"
This is just one example, I remember. There are more like this. But to deal with these hive has many like "where not" etc.
If your question is does the Hive have any PL/SQL support. Straight answer is no. But, we can check the UDF in hive and also, the PIG on Hadoop.