Forum Discussion
kusto345
Feb 18, 2020Copper Contributor
How do I use Kusto client to create table?
I am trying to automate provisioning of Kusto cluster. So far I have terraform to create the cluster, create the database. I have yet to find a way to create a table.
I went down the path of using python but I ran into an issue (see further below) so switched to java. With Java I am getting an error with the query syntax. Can someone point me to the correct syntax that I should be using to create tables with the client?
Java Error
Caused by: com.microsoft.azure.kusto.data.exceptions.DataWebException: BadRequest_SyntaxError: Request is invalid and cannot be executed.
Syntax error: Query could not be parsed: . Query: '.create table FlowState ( id:string, flow:string, flowRunId:string )'
Python Error (Note: I have 'adal' installed.)
Traceback (most recent call last):
File "table_creation.py", line 1, in <module>
from azure.kusto.data.exceptions import KustoServiceError
File "/.../python3.6/site-packages/azure_kusto_data-0.0.44-py3.6.egg/azure/kusto/data/__init__.py", line 3, in <module>
from .request import KustoClient, KustoConnectionStringBuilder, ClientRequestProperties
File "/.../python3.6/site-packages/azure_kusto_data-0.0.44-py3.6.egg/azure/kusto/data/request.py", line 17, in <module>
from .security import _AadHelper
File "/.../python3.6/site-packages/azure_kusto_data-0.0.44-py3.6.egg/azure/kusto/data/security.py", line 10, in <module>
from adal import AuthenticationContext, AdalError
ModuleNotFoundError: No module named 'adal'
- Daniel Dubovski
Microsoft
kusto345 , The error does suggest that you are missing adal.
It may be because you are working on a different environment where adal is missing (virtualenv, conda, etc..) or that you have an old version installed.
Could you kindly paste the output of pip freeze, and try and import adal in python REPL?- kusto345Copper Contributor
Daniel Dubovski thanks for responding and the pointer, apologies that it took me so long to respond.
I cleaned up my env and recreated it. I seem to have made progress but still unable to use the client sdk to create a table
'message': 'Caller is not authorized to perform this action', '@type': 'Kusto.DataNode.Exceptions.UnauthorizedDatabaseAccessException', '@message': "Principal 'aadapp=<sp>;<tenant-id>' is not authorized to access database '<database-name>'."
So I turned to azure cli to grant the role of "AllDatabasesAdmin" to my service principal. I however do not see any of the roles for ADX. As a result when I try to grant my sp access to the database it just does not find the role. I picked a role from the portal, there are two "AllDatabasesAdmin" and "AllDatabasesViewer"
az role assignment create --assignee <sp> --scope <resource-path-to-database> --role AllDatabasesAdmin.
I get the following exception
Role 'AllDatabasesAdmin' doesn't exist.