Apache Drill | Get table list from REST API - apache-drill

Any one can explain how to get table list via Drill REST API.
I have tried with show database -> use mysql.db -> show table list
Able to get DB list but not able to get table list from respective DB.
Thanks in advance.
EDIT FROM COMMENT
My JSON request like this first :
{ "queryType" : "SQL", "query" : "USE MYSQL.dbtest" }
I got default schema result, then I sent
{ "queryType" : "SQL", "query" : "SHOW TABLES" }
then i got exception like this
org.apache.drill.common.exceptions.UserRemoteException: VALIDATION ERROR: No default schema selected. Select a schema using 'USE schema' command [Error Id: e4e2d2f4-6f08-4ef9-9be3-ba3bbe2d20d9 on spark-slave:31010]

It is very hard to help with little information. Since you provided no information about your JSON request strings I have to assume.
First, https://drill.apache.org/docs/rest-api/#query shows that you can send a query to Drill. This might be what you have used.
Secondly, there is no command show table list. Even directly in Drill, this shouldn't work. The correct command, also to be found in the documentation under https://drill.apache.org/docs/show-tables/ is SHOW TABLES;
If you need any further help, please add more information.
EDIT
It seems that Drill is not "remembering" your USE command. Maybe a new session is being opened. To avoid needing to use USE, you could try including the database identifier in your SHOW statement.
{ "queryType" : "SQL", "query" : "SHOW MYSQL.dbtest.TABLES" }
I am not sure if that is possible, though. What should work is using the SELECT statement:
{ "queryType" : "SQL", "query" : "SELECT * FROM MYSQL.dbtest.<a_table_name>" }

Related

Zabbix 3.4 Bits Received and Sent

I simply want to see my download and upload data in the map section but i couldnt figure out the code.
For example = When i use this ( ''{HOSTNAME : net.if.speed[Interface ge.2.47()].last()}'' ) command it says UNKNOWN but I dont know where im doing wrong.
Also tried using ( net.if.in[Interface ge.2.47(Uplink)]:last()} ) but its still not showing any data.
You can use this:
In: {systemname.with.zabbix:ifInOctets[ppp0].last(0)}
Out: {systemname.with.zabbix:ifOutOctets[ppp0].last(0)}
Of course you have to replace the systemname and the interface name (ppp0)
You find the interface names in the items section of the host. (Of course you must have some kind of agent or snmp activated on that host)

Spring data Couchbase #n1ql.fields query

I'm trying to make a N1QL based query on Spring Data Couchbase. The documentation says
#n1ql.fields will be replaced by the list of fields (eg. for a SELECT clause) necessary to reconstruct the entity.
My repository implementation is this one:
#Query("#{#n1ql.fields} WHERE #{#n1ql.filter}")
List<User> findAllByFields(String fields);
And I'm calling this query as follows:
this.userRepository.findAllByFields("SELECT firstName FROM default");
I'm getting this error:
Caused by: org.springframework.data.couchbase.core.CouchbaseQueryExecutionException: Unable to execute query due to the following n1ql errors:
{"msg":"syntax error - at AS","code":3000}
After a little bit of researching, I also tryed:
#Query("SELECT #{#n1ql.fields} FROM #{#n1ql.bucket} WHERE #{#n1ql.filter}")
With this query, I don't get an error, I get all the documents stored but only the ID the other fields are set to null, when my query tries to get the firstName field.
this.userRepository.findAllByFields("firstName");
Anyone knows how to do such a query?
Thank you in advance.
You're misunderstanding the concept, I encourage you to give the documentation more time and see more examples. I'm not sure what exactly you're trying to achieve but I'll throw some examples.
Find all users (with all of their stored data)
#Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter}")
List<User> findAllUsers();
This will basically generate SELECT meta().id,_cas,* FROM bucket WHERE type='com.example.User'
Notice findAllUsers() does not take any parameters because there are no param placeholders defined in the #Query above.
Find all users where firstName like
#Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND firstName like $1")
List<User> findByFirstNameLike(String keyword);
This will generate something like the above query but with an extra where condition firstName like
Notice this method takes a keyword because there is a param placeholder defined $1.
Notice in the documentation it says
#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND test = $1
is equivalent to
SELECT #{#n1ql.fields} FROM #{#n1ql.bucket} WHERE
#{#n1ql.filter} AND test = $1
Now if you don't want to fetch all the data for user(s), you'll need to specify the fields being selected, read following links for more info
How to fetch a field from document using n1ql with spring-data-couchbase
https://docs.spring.io/spring-data/couchbase/docs/2.2.4.RELEASE/reference/html/#_dto_projections
I think you should try below query, that should resolve the issue to get fields based parameter you have sent as arguments.
Please refer blow query.
#Query("SELECT $1 FROM #{#n1q1.bucket} WHERE #{#n1ql.filter}")
List findByFirstName(String fieldName);
Here, bucket name resolve to the User entity and and n1ql.filter would be a default filter.

How do I associate my value with its key when writing to Firebase in Swift 3?

I'm working with Swift and Firebase to write profile info to my FireBase Database.
FIRAuth.auth()?.signIn(withEmail: userEmail!, password: userPassword!) { (user, error) in
self.ref = FIRDatabase.database().reference()
self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).setValue(String(describing: user))
self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).child("User Email").setValue([userEmail])
I expect the Database to read as:
UID
---UserFirstName: "Insert Name Here"
But instead I get:
UID
---UserFirstName
------0: "Insert Name Here"
I know I'm just missing something basic here. this is my first shot at Swift. Nothing else I've read seems to reference this issue. I'm sure I'm just not properly representing the "key-value" relationship correctly in the syntax of the code.
I fixed it by altering my code to look like this:
self.ref?.child("Users").child(FIRAuth.auth()!.currentUser!.uid).updateChildValues(["User Email": userEmail!])
the change to updateChildValues allowed me to not overwrite myself under the node each time, and the (["User Email": userEmail!]) piece allows me to attribute the value directly to the key.

'Relation does not exist' error after transferring to PostgreSQL

I have transfered my project from MySQL to PostgreSQL and tried to drop the column as result of previous issue, because after I removed the problematic column from models.py and saved. error didn't even disappear. Integer error transferring from MySQL to PostgreSQL
Tried both with and without quotes.
ALTER TABLE "UserProfile" DROP COLUMN how_many_new_notifications;
Or:
ALTER TABLE UserProfile DROP COLUMN how_many_new_notifications;
Getting the following:
ERROR: relation "UserProfile" does not exist
Here's a model, if helps:
class UserProfile(models.Model):
user = models.OneToOneField(User)
how_many_new_notifications = models.IntegerField(null=True,default=0)
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
I supposed it might have something to do with mixed-case but I have found no solution through all similar questions.
Yes, Postgresql is a case aware database but django is smart enough to know that. It converts all field and it generally converts the model name to a lower case table name. However the real problem here is that your model name will be prefixed by the app name. generally django table names are like:
<appname>_<modelname>
You can find out what exactly it is by:
from myapp.models import UserProfile
print (UserProfile._meta.db_table)
Obviously this needs to be typed into the django shell, which is invoked by ./manage.py shell the result of this print statement is what you should use in your query.
Client: DataGrip
Database engine: PostgreSQL
For me this worked opening a new console, because apparently from the IDE cache it was not recognizing the table I had created.
Steps to operate with the tables of a database:
Database (Left side panel of the IDE) >
Double Click on PostgreSQL - #localhost >
Double Click on the name of the database >
Right click on public schema >
New > Console
GL

Get Redmine custom field value to a file

I'm trying to create a text file that contains the value of a custom field I added on redmine. I tried to get it from an SQL query in the create method of the project_controller.rb (at line 80 on redmine 1.2.0) as follows :
sql = Mysql.new('localhost','root','pass','bitnami_redmine')
rq = sql.query("SELECT value
FROM custom_values
INNER JOIN projects
ON custom_values.customized_id=projects.id
WHERE custom_values.custom_field_id=7
AND projects.name='#{#project.name}'")
rq.each_hash { |h|
File.open('pleasework.txt', 'w') { |myfile|
myfile.write(h['value'])
}
}
sql.close
This works fine if I test it in a separate file (with an existing project name instead of #project.name) so it may be a syntax issue but I can't find what it is. I'd also be glad to hear any other solution to get that value.
Thanks !
(there's a very similar post here but none of the solutions actually worked)
First, you could use Project.connection.query instead of your own Mysql instance. Second, I would try to log the SQL RAILS_DEFAULT_LOGGER.info "SELECT ..." and check if it's ok... And the third, I would use identifier instead of name.
I ended up simply using params["project"]["custom_field_values"]["x"] where x is the custom field's id. I still don't know why the sql query didn't work but well, this is much simpler and faster.