Welcome to mirror list, hosted at ThFree Co, Russian Federation.

formatter_spec.rb « client « click_house « spec « click_house-client « gems - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca57187b098d8adbbdb5ce80f505428de780207d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ClickHouse::Client::Formatter do
  it 'formats values according to types in metadata' do
    # this query here is just for documentation purposes, it generates the response below
    _query = <<~SQL.squish
      SELECT toUInt64(1) as uint64,
             toDateTime64('2016-06-15 23:00:00', 6, 'UTC') as datetime64_6,
             INTERVAL 1 second as interval_second,
             INTERVAL 1 millisecond as interval_millisecond
    SQL

    response_json = <<~JSON
{
	"meta":
	[
		{
			"name": "uint64",
			"type": "UInt64"
		},
		{
			"name": "datetime64_6",
			"type": "DateTime64(6, 'UTC')"
		},
		{
			"name": "interval_second",
			"type": "IntervalSecond"
		},
		{
		   "name": "interval_millisecond",
		   "type": "IntervalMillisecond"
		}
	],

	"data":
	[
		{
			"uint64": "1",
			"datetime64_6": "2016-06-15 23:00:00.000000",
			"interval_second": "1",
			"interval_millisecond": "1"
		}
	],

	"rows": 1,

	"statistics":
	{
		"elapsed": 0.002101,
		"rows_read": 1,
		"bytes_read": 1
	}
}
    JSON

    parsed_response = JSON.parse(response_json)
    formatted_response = described_class.format(parsed_response)

    expect(formatted_response).to(
      eq(
        [{ "uint64" => 1,
           "datetime64_6" => ActiveSupport::TimeZone["UTC"].parse("2016-06-15 23:00:00"),
           "interval_second" => 1.second,
           "interval_millisecond" => 0.001.seconds }]
      )
    )
  end
end