0

Please, suggest the best way to export data from clickhouse using python.

Right now I am using this code but have an error stating that hotsname can't be reached.

from clickhouse_driver import Client
client=Client(host='http://ipaddress',user='user',password='pass',port=8123)
print(client.execute('select * from table limit 5'))

Are there any other ways to do that?

1
  • 1
    Could you show the exact error you get? Commented Dec 8, 2018 at 16:49

2 Answers 2

1

clickhouse-driver communicates with ClickHouse over native protocol not HTTP, so:

  • host should contain hostname or IP (not HTTP URL)
  • port should be 9000 (or 9440 for secure connection)

I would rely on the generator function execute-iter to stream an export data:

from clickhouse_driver import Client

client = Client(host='localhost')

data = client.execute_iter('SELECT * FROM numbers(1 * 1000 * 1000)')
row_count = 0

for row in data:
    # do smth per row
    row_count += 1

print(f"Row count is {row_count}.")
# Row count is 1000000.
Sign up to request clarification or add additional context in comments.

Comments

0

In the code sample you provided,

from clickhouse_driver import Client
client=Client(host='http://ipaddress',user='user',password='pass',port=8123)
print(client.execute('select * from table limit 5'))

you put http://ipaddress which is not a valid hostname, if you change this to a valid hostname, it should work fine.

2 Comments

Thank you, actually I use the valid hostname (just put ipaddress as an example here)
Did you also put http:// because that's where I'd assume it goes wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.