presto-client 0.4.14 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f05ad7fb71f97a4804e24451a201d8043d3518a
4
- data.tar.gz: 369f6523a275ead5350cf42a95f0c22d56b52c22
3
+ metadata.gz: 160eac662fe5a07e72ed26e97ac08e7c315226a1
4
+ data.tar.gz: 50b4e8e1dbd4dcbe4e5990e95aaa1be5296e44b9
5
5
  SHA512:
6
- metadata.gz: 938b3b5ae20a354a659713f3ad29952619403d45f01dbf41a1ca8907659250a7b5597787fdcfc3b028e049cc27e819c39b6721b38a0ab5695d86dcbc6b55e911
7
- data.tar.gz: 81353b8f0f53784533c282e2471f1c79d4f28de2cdd8506ceb7e291fb8d7fb3c7d979342d952dc7e47f09b1c4b3a7833abcefed85b425bf9a7ed25c59ee88ea5
6
+ metadata.gz: 4b562d91bd4440c249894c8d1569e3b67705220411db41b27a950c3780312609b26a6378572778a1db4b7cacdc487022e2a59cfb42a6a4f1986d85c2eb1fa1f0
7
+ data.tar.gz: 24e48484fbafa9de9034aedbd700a3f4ef81f4fd48e4914b14f90200e54b921b1815d5552a447f189dd1c04b9a625dd1f4aafe403c63fe970a69cac1cb10be0c
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ 2016-08-03 version 0.4.15:
2
+
3
+ * decode method of model classes validate Hash type
4
+
1
5
  2016-08-02 version 0.4.14:
2
6
 
3
7
  * Added support for resuming fetching query results by using new `Query.resume(next_uri, options)` method (@tetrakai++)
@@ -77,6 +77,9 @@ module Presto::Client
77
77
 
78
78
  module PlanNode
79
79
  def self.decode(hash)
80
+ unless hash.is_a?(Hash)
81
+ raise TypeError, "Can't convert #{hash.class} to Hash"
82
+ end
80
83
  model_class = case hash["@type"]
81
84
  when "output" then OutputNode
82
85
  when "project" then ProjectNode
@@ -122,6 +125,9 @@ module Presto::Client
122
125
  class << DistributionSnapshot =
123
126
  Base.new(:max_error, :count, :total, :p01, :p05, :p10, :p25, :p50, :p75, :p90, :p95, :p99, :min, :max)
124
127
  def decode(hash)
128
+ unless hash.is_a?(Hash)
129
+ raise TypeError, "Can't convert #{hash.class} to Hash"
130
+ end
125
131
  obj = allocate
126
132
  obj.send(:initialize_struct,
127
133
  hash["maxError"],
@@ -147,6 +153,9 @@ module Presto::Client
147
153
  class << EquiJoinClause =
148
154
  Base.new(:left, :right, :probe, :index)
149
155
  def decode(hash)
156
+ unless hash.is_a?(Hash)
157
+ raise TypeError, "Can't convert #{hash.class} to Hash"
158
+ end
150
159
  obj = allocate
151
160
  obj.send(:initialize_struct,
152
161
  hash["left"],
@@ -161,6 +170,9 @@ module Presto::Client
161
170
  class << WriterTarget =
162
171
  Base.new(:type, :handle)
163
172
  def decode(hash)
173
+ unless hash.is_a?(Hash)
174
+ raise TypeError, "Can't convert #{hash.class} to Hash"
175
+ end
164
176
  obj = allocate
165
177
  model_class = case hash["@type"]
166
178
  when "CreateHandle" then OutputTableHandle
@@ -178,6 +190,9 @@ module Presto::Client
178
190
  class << DeleteHandle =
179
191
  Base.new(:handle)
180
192
  def decode(hash)
193
+ unless hash.is_a?(Hash)
194
+ raise TypeError, "Can't convert #{hash.class} to Hash"
195
+ end
181
196
  obj = allocate
182
197
  obj.send(:initialize_struct,
183
198
  TableHandle.decode(hash['handle'])
@@ -191,6 +206,9 @@ module Presto::Client
191
206
  class << PageBufferInfo =
192
207
  Base.new(:partition, :buffered_pages, :queued_pages, :buffered_bytes, :pages_added)
193
208
  def decode(hash)
209
+ unless hash.is_a?(Hash)
210
+ raise TypeError, "Can't convert #{hash.class} to Hash"
211
+ end
194
212
  obj = allocate
195
213
  obj.send(:initialize_struct,
196
214
  hash["partition"],
@@ -210,6 +228,9 @@ module Presto::Client
210
228
  class << AggregationNode =
211
229
  Base.new(:id, :source, :group_by, :aggregations, :functions, :masks, :step, :sample_weight, :confidence, :hash_symbol)
212
230
  def decode(hash)
231
+ unless hash.is_a?(Hash)
232
+ raise TypeError, "Can't convert #{hash.class} to Hash"
233
+ end
213
234
  obj = allocate
214
235
  obj.send(:initialize_struct,
215
236
  hash["id"],
@@ -230,6 +251,9 @@ module Presto::Client
230
251
  class << BufferInfo =
231
252
  Base.new(:buffer_id, :finished, :buffered_pages, :pages_sent, :page_buffer_info)
232
253
  def decode(hash)
254
+ unless hash.is_a?(Hash)
255
+ raise TypeError, "Can't convert #{hash.class} to Hash"
256
+ end
233
257
  obj = allocate
234
258
  obj.send(:initialize_struct,
235
259
  hash["bufferId"] && TaskId.new(hash["bufferId"]),
@@ -245,6 +269,9 @@ module Presto::Client
245
269
  class << ClientColumn =
246
270
  Base.new(:name, :type, :type_signature)
247
271
  def decode(hash)
272
+ unless hash.is_a?(Hash)
273
+ raise TypeError, "Can't convert #{hash.class} to Hash"
274
+ end
248
275
  obj = allocate
249
276
  obj.send(:initialize_struct,
250
277
  hash["name"],
@@ -258,6 +285,9 @@ module Presto::Client
258
285
  class << ClientStageStats =
259
286
  Base.new(:stage_id, :state, :done, :nodes, :total_splits, :queued_splits, :running_splits, :completed_splits, :user_time_millis, :cpu_time_millis, :wall_time_millis, :processed_rows, :processed_bytes, :sub_stages)
260
287
  def decode(hash)
288
+ unless hash.is_a?(Hash)
289
+ raise TypeError, "Can't convert #{hash.class} to Hash"
290
+ end
261
291
  obj = allocate
262
292
  obj.send(:initialize_struct,
263
293
  hash["stageId"],
@@ -282,6 +312,9 @@ module Presto::Client
282
312
  class << ClientTypeSignature =
283
313
  Base.new(:raw_type, :type_arguments, :literal_arguments, :arguments)
284
314
  def decode(hash)
315
+ unless hash.is_a?(Hash)
316
+ raise TypeError, "Can't convert #{hash.class} to Hash"
317
+ end
285
318
  obj = allocate
286
319
  obj.send(:initialize_struct,
287
320
  hash["rawType"],
@@ -296,6 +329,9 @@ module Presto::Client
296
329
  class << ClientTypeSignatureParameter =
297
330
  Base.new(:kind, :value)
298
331
  def decode(hash)
332
+ unless hash.is_a?(Hash)
333
+ raise TypeError, "Can't convert #{hash.class} to Hash"
334
+ end
299
335
  obj = allocate
300
336
  obj.send(:initialize_struct,
301
337
  hash["kind"] && hash["kind"].downcase.to_sym,
@@ -308,6 +344,9 @@ module Presto::Client
308
344
  class << Column =
309
345
  Base.new(:name, :type)
310
346
  def decode(hash)
347
+ unless hash.is_a?(Hash)
348
+ raise TypeError, "Can't convert #{hash.class} to Hash"
349
+ end
311
350
  obj = allocate
312
351
  obj.send(:initialize_struct,
313
352
  hash["name"],
@@ -320,6 +359,9 @@ module Presto::Client
320
359
  class << DeleteNode =
321
360
  Base.new(:id, :source, :target, :row_id, :outputs)
322
361
  def decode(hash)
362
+ unless hash.is_a?(Hash)
363
+ raise TypeError, "Can't convert #{hash.class} to Hash"
364
+ end
323
365
  obj = allocate
324
366
  obj.send(:initialize_struct,
325
367
  hash["id"],
@@ -335,6 +377,9 @@ module Presto::Client
335
377
  class << DistinctLimitNode =
336
378
  Base.new(:id, :source, :limit, :hash_symbol)
337
379
  def decode(hash)
380
+ unless hash.is_a?(Hash)
381
+ raise TypeError, "Can't convert #{hash.class} to Hash"
382
+ end
338
383
  obj = allocate
339
384
  obj.send(:initialize_struct,
340
385
  hash["id"],
@@ -349,6 +394,9 @@ module Presto::Client
349
394
  class << DriverStats =
350
395
  Base.new(:create_time, :start_time, :end_time, :queued_time, :elapsed_time, :memory_reservation, :system_memory_reservation, :total_scheduled_time, :total_cpu_time, :total_user_time, :total_blocked_time, :fully_blocked, :blocked_reasons, :raw_input_data_size, :raw_input_positions, :raw_input_read_time, :processed_input_data_size, :processed_input_positions, :output_data_size, :output_positions, :operator_stats)
351
396
  def decode(hash)
397
+ unless hash.is_a?(Hash)
398
+ raise TypeError, "Can't convert #{hash.class} to Hash"
399
+ end
352
400
  obj = allocate
353
401
  obj.send(:initialize_struct,
354
402
  hash["createTime"],
@@ -380,6 +428,9 @@ module Presto::Client
380
428
  class << EnforceSingleRowNode =
381
429
  Base.new(:id, :source)
382
430
  def decode(hash)
431
+ unless hash.is_a?(Hash)
432
+ raise TypeError, "Can't convert #{hash.class} to Hash"
433
+ end
383
434
  obj = allocate
384
435
  obj.send(:initialize_struct,
385
436
  hash["id"],
@@ -392,6 +443,9 @@ module Presto::Client
392
443
  class << ErrorCode =
393
444
  Base.new(:code, :name)
394
445
  def decode(hash)
446
+ unless hash.is_a?(Hash)
447
+ raise TypeError, "Can't convert #{hash.class} to Hash"
448
+ end
395
449
  obj = allocate
396
450
  obj.send(:initialize_struct,
397
451
  hash["code"],
@@ -404,6 +458,9 @@ module Presto::Client
404
458
  class << ErrorLocation =
405
459
  Base.new(:line_number, :column_number)
406
460
  def decode(hash)
461
+ unless hash.is_a?(Hash)
462
+ raise TypeError, "Can't convert #{hash.class} to Hash"
463
+ end
407
464
  obj = allocate
408
465
  obj.send(:initialize_struct,
409
466
  hash["lineNumber"],
@@ -416,6 +473,9 @@ module Presto::Client
416
473
  class << ExchangeNode =
417
474
  Base.new(:id, :type, :partition_function, :sources, :outputs, :inputs)
418
475
  def decode(hash)
476
+ unless hash.is_a?(Hash)
477
+ raise TypeError, "Can't convert #{hash.class} to Hash"
478
+ end
419
479
  obj = allocate
420
480
  obj.send(:initialize_struct,
421
481
  hash["id"],
@@ -432,6 +492,9 @@ module Presto::Client
432
492
  class << ExecutionFailureInfo =
433
493
  Base.new(:type, :message, :cause, :suppressed, :stack, :error_location, :error_code)
434
494
  def decode(hash)
495
+ unless hash.is_a?(Hash)
496
+ raise TypeError, "Can't convert #{hash.class} to Hash"
497
+ end
435
498
  obj = allocate
436
499
  obj.send(:initialize_struct,
437
500
  hash["type"],
@@ -449,6 +512,9 @@ module Presto::Client
449
512
  class << FailureInfo =
450
513
  Base.new(:type, :message, :cause, :suppressed, :stack, :error_location)
451
514
  def decode(hash)
515
+ unless hash.is_a?(Hash)
516
+ raise TypeError, "Can't convert #{hash.class} to Hash"
517
+ end
452
518
  obj = allocate
453
519
  obj.send(:initialize_struct,
454
520
  hash["type"],
@@ -465,6 +531,9 @@ module Presto::Client
465
531
  class << FilterNode =
466
532
  Base.new(:id, :source, :predicate)
467
533
  def decode(hash)
534
+ unless hash.is_a?(Hash)
535
+ raise TypeError, "Can't convert #{hash.class} to Hash"
536
+ end
468
537
  obj = allocate
469
538
  obj.send(:initialize_struct,
470
539
  hash["id"],
@@ -478,6 +547,9 @@ module Presto::Client
478
547
  class << IndexHandle =
479
548
  Base.new(:connector_id, :transaction_handle, :connector_handle)
480
549
  def decode(hash)
550
+ unless hash.is_a?(Hash)
551
+ raise TypeError, "Can't convert #{hash.class} to Hash"
552
+ end
481
553
  obj = allocate
482
554
  obj.send(:initialize_struct,
483
555
  hash["connectorId"],
@@ -491,6 +563,9 @@ module Presto::Client
491
563
  class << IndexJoinNode =
492
564
  Base.new(:id, :type, :probe_source, :index_source, :criteria, :probe_hash_symbol, :index_hash_symbol)
493
565
  def decode(hash)
566
+ unless hash.is_a?(Hash)
567
+ raise TypeError, "Can't convert #{hash.class} to Hash"
568
+ end
494
569
  obj = allocate
495
570
  obj.send(:initialize_struct,
496
571
  hash["id"],
@@ -508,6 +583,9 @@ module Presto::Client
508
583
  class << IndexSourceNode =
509
584
  Base.new(:id, :index_handle, :table_handle, :lookup_symbols, :output_symbols, :assignments, :effective_tuple_domain)
510
585
  def decode(hash)
586
+ unless hash.is_a?(Hash)
587
+ raise TypeError, "Can't convert #{hash.class} to Hash"
588
+ end
511
589
  obj = allocate
512
590
  obj.send(:initialize_struct,
513
591
  hash["id"],
@@ -525,6 +603,9 @@ module Presto::Client
525
603
  class << Input =
526
604
  Base.new(:connector_id, :schema, :table, :columns)
527
605
  def decode(hash)
606
+ unless hash.is_a?(Hash)
607
+ raise TypeError, "Can't convert #{hash.class} to Hash"
608
+ end
528
609
  obj = allocate
529
610
  obj.send(:initialize_struct,
530
611
  hash["connectorId"],
@@ -539,6 +620,9 @@ module Presto::Client
539
620
  class << InsertTableHandle =
540
621
  Base.new(:connector_id, :transaction_handle, :connector_handle)
541
622
  def decode(hash)
623
+ unless hash.is_a?(Hash)
624
+ raise TypeError, "Can't convert #{hash.class} to Hash"
625
+ end
542
626
  obj = allocate
543
627
  obj.send(:initialize_struct,
544
628
  hash["connectorId"],
@@ -552,6 +636,9 @@ module Presto::Client
552
636
  class << JoinNode =
553
637
  Base.new(:id, :type, :left, :right, :criteria, :left_hash_symbol, :right_hash_symbol)
554
638
  def decode(hash)
639
+ unless hash.is_a?(Hash)
640
+ raise TypeError, "Can't convert #{hash.class} to Hash"
641
+ end
555
642
  obj = allocate
556
643
  obj.send(:initialize_struct,
557
644
  hash["id"],
@@ -569,6 +656,9 @@ module Presto::Client
569
656
  class << LimitNode =
570
657
  Base.new(:id, :source, :count)
571
658
  def decode(hash)
659
+ unless hash.is_a?(Hash)
660
+ raise TypeError, "Can't convert #{hash.class} to Hash"
661
+ end
572
662
  obj = allocate
573
663
  obj.send(:initialize_struct,
574
664
  hash["id"],
@@ -582,6 +672,9 @@ module Presto::Client
582
672
  class << MarkDistinctNode =
583
673
  Base.new(:id, :source, :marker_symbol, :distinct_symbols, :hash_symbol)
584
674
  def decode(hash)
675
+ unless hash.is_a?(Hash)
676
+ raise TypeError, "Can't convert #{hash.class} to Hash"
677
+ end
585
678
  obj = allocate
586
679
  obj.send(:initialize_struct,
587
680
  hash["id"],
@@ -597,6 +690,9 @@ module Presto::Client
597
690
  class << MetadataDeleteNode =
598
691
  Base.new(:id, :target, :output, :table_layout)
599
692
  def decode(hash)
693
+ unless hash.is_a?(Hash)
694
+ raise TypeError, "Can't convert #{hash.class} to Hash"
695
+ end
600
696
  obj = allocate
601
697
  obj.send(:initialize_struct,
602
698
  hash["id"],
@@ -611,6 +707,9 @@ module Presto::Client
611
707
  class << OperatorStats =
612
708
  Base.new(:operator_id, :plan_node_id, :operator_type, :add_input_calls, :add_input_wall, :add_input_cpu, :add_input_user, :input_data_size, :input_positions, :get_output_calls, :get_output_wall, :get_output_cpu, :get_output_user, :output_data_size, :output_positions, :blocked_wall, :finish_calls, :finish_wall, :finish_cpu, :finish_user, :memory_reservation, :system_memory_reservation, :blocked_reason, :info)
613
709
  def decode(hash)
710
+ unless hash.is_a?(Hash)
711
+ raise TypeError, "Can't convert #{hash.class} to Hash"
712
+ end
614
713
  obj = allocate
615
714
  obj.send(:initialize_struct,
616
715
  hash["operatorId"],
@@ -645,6 +744,9 @@ module Presto::Client
645
744
  class << OutputNode =
646
745
  Base.new(:id, :source, :columns, :outputs)
647
746
  def decode(hash)
747
+ unless hash.is_a?(Hash)
748
+ raise TypeError, "Can't convert #{hash.class} to Hash"
749
+ end
648
750
  obj = allocate
649
751
  obj.send(:initialize_struct,
650
752
  hash["id"],
@@ -659,6 +761,9 @@ module Presto::Client
659
761
  class << OutputTableHandle =
660
762
  Base.new(:connector_id, :transaction_handle, :connector_handle)
661
763
  def decode(hash)
764
+ unless hash.is_a?(Hash)
765
+ raise TypeError, "Can't convert #{hash.class} to Hash"
766
+ end
662
767
  obj = allocate
663
768
  obj.send(:initialize_struct,
664
769
  hash["connectorId"],
@@ -672,6 +777,9 @@ module Presto::Client
672
777
  class << PartitionFunctionBinding =
673
778
  Base.new(:function_handle, :partitioning_columns, :hash_column, :replicate_nulls, :partition_count)
674
779
  def decode(hash)
780
+ unless hash.is_a?(Hash)
781
+ raise TypeError, "Can't convert #{hash.class} to Hash"
782
+ end
675
783
  obj = allocate
676
784
  obj.send(:initialize_struct,
677
785
  hash["functionHandle"] && hash["functionHandle"].downcase.to_sym,
@@ -687,6 +795,9 @@ module Presto::Client
687
795
  class << PipelineStats =
688
796
  Base.new(:input_pipeline, :output_pipeline, :total_drivers, :queued_drivers, :queued_partitioned_drivers, :running_drivers, :running_partitioned_drivers, :completed_drivers, :memory_reservation, :system_memory_reservation, :queued_time, :elapsed_time, :total_scheduled_time, :total_cpu_time, :total_user_time, :total_blocked_time, :fully_blocked, :blocked_reasons, :raw_input_data_size, :raw_input_positions, :processed_input_data_size, :processed_input_positions, :output_data_size, :output_positions, :operator_summaries, :drivers)
689
797
  def decode(hash)
798
+ unless hash.is_a?(Hash)
799
+ raise TypeError, "Can't convert #{hash.class} to Hash"
800
+ end
690
801
  obj = allocate
691
802
  obj.send(:initialize_struct,
692
803
  hash["inputPipeline"],
@@ -723,6 +834,9 @@ module Presto::Client
723
834
  class << PlanFragment =
724
835
  Base.new(:id, :root, :symbols, :output_layout, :distribution, :partitioned_source, :partition_function)
725
836
  def decode(hash)
837
+ unless hash.is_a?(Hash)
838
+ raise TypeError, "Can't convert #{hash.class} to Hash"
839
+ end
726
840
  obj = allocate
727
841
  obj.send(:initialize_struct,
728
842
  hash["id"],
@@ -740,6 +854,9 @@ module Presto::Client
740
854
  class << ProjectNode =
741
855
  Base.new(:id, :source, :assignments)
742
856
  def decode(hash)
857
+ unless hash.is_a?(Hash)
858
+ raise TypeError, "Can't convert #{hash.class} to Hash"
859
+ end
743
860
  obj = allocate
744
861
  obj.send(:initialize_struct,
745
862
  hash["id"],
@@ -753,6 +870,9 @@ module Presto::Client
753
870
  class << QueryError =
754
871
  Base.new(:message, :sql_state, :error_code, :error_name, :error_type, :error_location, :failure_info)
755
872
  def decode(hash)
873
+ unless hash.is_a?(Hash)
874
+ raise TypeError, "Can't convert #{hash.class} to Hash"
875
+ end
756
876
  obj = allocate
757
877
  obj.send(:initialize_struct,
758
878
  hash["message"],
@@ -770,6 +890,9 @@ module Presto::Client
770
890
  class << QueryInfo =
771
891
  Base.new(:query_id, :session, :state, :memory_pool, :scheduled, :self, :field_names, :query, :query_stats, :set_session_properties, :reset_session_properties, :started_transaction_id, :clear_transaction_id, :update_type, :output_stage, :failure_info, :error_code, :inputs)
772
892
  def decode(hash)
893
+ unless hash.is_a?(Hash)
894
+ raise TypeError, "Can't convert #{hash.class} to Hash"
895
+ end
773
896
  obj = allocate
774
897
  obj.send(:initialize_struct,
775
898
  hash["queryId"],
@@ -798,6 +921,9 @@ module Presto::Client
798
921
  class << QueryResults =
799
922
  Base.new(:id, :info_uri, :partial_cancel_uri, :next_uri, :columns, :data, :stats, :error, :update_type, :update_count)
800
923
  def decode(hash)
924
+ unless hash.is_a?(Hash)
925
+ raise TypeError, "Can't convert #{hash.class} to Hash"
926
+ end
801
927
  obj = allocate
802
928
  obj.send(:initialize_struct,
803
929
  hash["id"],
@@ -818,6 +944,9 @@ module Presto::Client
818
944
  class << QueryStats =
819
945
  Base.new(:create_time, :execution_start_time, :last_heartbeat, :end_time, :elapsed_time, :queued_time, :analysis_time, :distributed_planning_time, :total_planning_time, :finishing_time, :total_tasks, :running_tasks, :completed_tasks, :total_drivers, :queued_drivers, :running_drivers, :completed_drivers, :cumulative_memory, :total_memory_reservation, :peak_memory_reservation, :total_scheduled_time, :total_cpu_time, :total_user_time, :total_blocked_time, :fully_blocked, :blocked_reasons, :raw_input_data_size, :raw_input_positions, :processed_input_data_size, :processed_input_positions, :output_data_size, :output_positions)
820
946
  def decode(hash)
947
+ unless hash.is_a?(Hash)
948
+ raise TypeError, "Can't convert #{hash.class} to Hash"
949
+ end
821
950
  obj = allocate
822
951
  obj.send(:initialize_struct,
823
952
  hash["createTime"],
@@ -860,6 +989,9 @@ module Presto::Client
860
989
  class << RemoteSourceNode =
861
990
  Base.new(:id, :source_fragment_ids, :outputs)
862
991
  def decode(hash)
992
+ unless hash.is_a?(Hash)
993
+ raise TypeError, "Can't convert #{hash.class} to Hash"
994
+ end
863
995
  obj = allocate
864
996
  obj.send(:initialize_struct,
865
997
  hash["id"],
@@ -873,6 +1005,9 @@ module Presto::Client
873
1005
  class << RowNumberNode =
874
1006
  Base.new(:id, :source, :partition_by, :row_number_symbol, :max_row_count_per_partition, :hash_symbol)
875
1007
  def decode(hash)
1008
+ unless hash.is_a?(Hash)
1009
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1010
+ end
876
1011
  obj = allocate
877
1012
  obj.send(:initialize_struct,
878
1013
  hash["id"],
@@ -889,6 +1024,9 @@ module Presto::Client
889
1024
  class << SampleNode =
890
1025
  Base.new(:id, :source, :sample_ratio, :sample_type, :rescaled, :sample_weight_symbol)
891
1026
  def decode(hash)
1027
+ unless hash.is_a?(Hash)
1028
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1029
+ end
892
1030
  obj = allocate
893
1031
  obj.send(:initialize_struct,
894
1032
  hash["id"],
@@ -905,6 +1043,9 @@ module Presto::Client
905
1043
  class << SemiJoinNode =
906
1044
  Base.new(:id, :source, :filtering_source, :source_join_symbol, :filtering_source_join_symbol, :semi_join_output, :source_hash_symbol, :filtering_source_hash_symbol)
907
1045
  def decode(hash)
1046
+ unless hash.is_a?(Hash)
1047
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1048
+ end
908
1049
  obj = allocate
909
1050
  obj.send(:initialize_struct,
910
1051
  hash["id"],
@@ -923,6 +1064,9 @@ module Presto::Client
923
1064
  class << SessionRepresentation =
924
1065
  Base.new(:query_id, :transaction_id, :client_transaction_support, :user, :principal, :source, :catalog, :schema, :time_zone_key, :locale, :remote_user_address, :user_agent, :start_time, :system_properties, :catalog_properties)
925
1066
  def decode(hash)
1067
+ unless hash.is_a?(Hash)
1068
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1069
+ end
926
1070
  obj = allocate
927
1071
  obj.send(:initialize_struct,
928
1072
  hash["queryId"],
@@ -948,6 +1092,9 @@ module Presto::Client
948
1092
  class << SharedBufferInfo =
949
1093
  Base.new(:state, :can_add_buffers, :can_add_pages, :total_buffered_bytes, :total_buffered_pages, :total_queued_pages, :total_pages_sent, :buffers)
950
1094
  def decode(hash)
1095
+ unless hash.is_a?(Hash)
1096
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1097
+ end
951
1098
  obj = allocate
952
1099
  obj.send(:initialize_struct,
953
1100
  hash["state"] && hash["state"].downcase.to_sym,
@@ -966,6 +1113,9 @@ module Presto::Client
966
1113
  class << Signature =
967
1114
  Base.new(:name, :kind, :type_parameter_requirements, :return_type, :argument_types, :variable_arity)
968
1115
  def decode(hash)
1116
+ unless hash.is_a?(Hash)
1117
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1118
+ end
969
1119
  obj = allocate
970
1120
  obj.send(:initialize_struct,
971
1121
  hash["name"],
@@ -982,6 +1132,9 @@ module Presto::Client
982
1132
  class << SortNode =
983
1133
  Base.new(:id, :source, :order_by, :orderings)
984
1134
  def decode(hash)
1135
+ unless hash.is_a?(Hash)
1136
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1137
+ end
985
1138
  obj = allocate
986
1139
  obj.send(:initialize_struct,
987
1140
  hash["id"],
@@ -996,6 +1149,9 @@ module Presto::Client
996
1149
  class << StageInfo =
997
1150
  Base.new(:stage_id, :state, :self, :plan, :types, :stage_stats, :tasks, :sub_stages, :failure_cause)
998
1151
  def decode(hash)
1152
+ unless hash.is_a?(Hash)
1153
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1154
+ end
999
1155
  obj = allocate
1000
1156
  obj.send(:initialize_struct,
1001
1157
  hash["stageId"] && StageId.new(hash["stageId"]),
@@ -1015,6 +1171,9 @@ module Presto::Client
1015
1171
  class << StageStats =
1016
1172
  Base.new(:scheduling_complete, :get_split_distribution, :schedule_task_distribution, :add_split_distribution, :total_tasks, :running_tasks, :completed_tasks, :total_drivers, :queued_drivers, :running_drivers, :completed_drivers, :cumulative_memory, :total_memory_reservation, :total_scheduled_time, :total_cpu_time, :total_user_time, :total_blocked_time, :fully_blocked, :blocked_reasons, :raw_input_data_size, :raw_input_positions, :processed_input_data_size, :processed_input_positions, :output_data_size, :output_positions)
1017
1173
  def decode(hash)
1174
+ unless hash.is_a?(Hash)
1175
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1176
+ end
1018
1177
  obj = allocate
1019
1178
  obj.send(:initialize_struct,
1020
1179
  hash["schedulingComplete"],
@@ -1050,6 +1209,9 @@ module Presto::Client
1050
1209
  class << StatementStats =
1051
1210
  Base.new(:state, :scheduled, :nodes, :total_splits, :queued_splits, :running_splits, :completed_splits, :user_time_millis, :cpu_time_millis, :wall_time_millis, :processed_rows, :processed_bytes, :root_stage)
1052
1211
  def decode(hash)
1212
+ unless hash.is_a?(Hash)
1213
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1214
+ end
1053
1215
  obj = allocate
1054
1216
  obj.send(:initialize_struct,
1055
1217
  hash["state"],
@@ -1073,6 +1235,9 @@ module Presto::Client
1073
1235
  class << TableFinishNode =
1074
1236
  Base.new(:id, :source, :target, :outputs)
1075
1237
  def decode(hash)
1238
+ unless hash.is_a?(Hash)
1239
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1240
+ end
1076
1241
  obj = allocate
1077
1242
  obj.send(:initialize_struct,
1078
1243
  hash["id"],
@@ -1087,6 +1252,9 @@ module Presto::Client
1087
1252
  class << TableHandle =
1088
1253
  Base.new(:connector_id, :connector_handle)
1089
1254
  def decode(hash)
1255
+ unless hash.is_a?(Hash)
1256
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1257
+ end
1090
1258
  obj = allocate
1091
1259
  obj.send(:initialize_struct,
1092
1260
  hash["connectorId"],
@@ -1099,6 +1267,9 @@ module Presto::Client
1099
1267
  class << TableLayoutHandle =
1100
1268
  Base.new(:connector_id, :transaction_handle, :connector_handle)
1101
1269
  def decode(hash)
1270
+ unless hash.is_a?(Hash)
1271
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1272
+ end
1102
1273
  obj = allocate
1103
1274
  obj.send(:initialize_struct,
1104
1275
  hash["connectorId"],
@@ -1112,6 +1283,9 @@ module Presto::Client
1112
1283
  class << TableScanNode =
1113
1284
  Base.new(:id, :table, :output_symbols, :assignments, :layout, :current_constraint, :original_constraint)
1114
1285
  def decode(hash)
1286
+ unless hash.is_a?(Hash)
1287
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1288
+ end
1115
1289
  obj = allocate
1116
1290
  obj.send(:initialize_struct,
1117
1291
  hash["id"],
@@ -1129,6 +1303,9 @@ module Presto::Client
1129
1303
  class << TableWriterNode =
1130
1304
  Base.new(:id, :source, :target, :columns, :column_names, :outputs, :sample_weight_symbol)
1131
1305
  def decode(hash)
1306
+ unless hash.is_a?(Hash)
1307
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1308
+ end
1132
1309
  obj = allocate
1133
1310
  obj.send(:initialize_struct,
1134
1311
  hash["id"],
@@ -1146,6 +1323,9 @@ module Presto::Client
1146
1323
  class << TaskInfo =
1147
1324
  Base.new(:task_id, :task_instance_id, :version, :state, :self, :last_heartbeat, :output_buffers, :no_more_splits, :stats, :failures)
1148
1325
  def decode(hash)
1326
+ unless hash.is_a?(Hash)
1327
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1328
+ end
1149
1329
  obj = allocate
1150
1330
  obj.send(:initialize_struct,
1151
1331
  hash["taskId"] && TaskId.new(hash["taskId"]),
@@ -1166,6 +1346,9 @@ module Presto::Client
1166
1346
  class << TaskStats =
1167
1347
  Base.new(:create_time, :first_start_time, :last_start_time, :end_time, :elapsed_time, :queued_time, :total_drivers, :queued_drivers, :queued_partitioned_drivers, :running_drivers, :running_partitioned_drivers, :completed_drivers, :cumulative_memory, :memory_reservation, :system_memory_reservation, :total_scheduled_time, :total_cpu_time, :total_user_time, :total_blocked_time, :fully_blocked, :blocked_reasons, :raw_input_data_size, :raw_input_positions, :processed_input_data_size, :processed_input_positions, :output_data_size, :output_positions, :pipelines)
1168
1348
  def decode(hash)
1349
+ unless hash.is_a?(Hash)
1350
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1351
+ end
1169
1352
  obj = allocate
1170
1353
  obj.send(:initialize_struct,
1171
1354
  hash["createTime"],
@@ -1204,6 +1387,9 @@ module Presto::Client
1204
1387
  class << TopNNode =
1205
1388
  Base.new(:id, :source, :count, :order_by, :orderings, :partial)
1206
1389
  def decode(hash)
1390
+ unless hash.is_a?(Hash)
1391
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1392
+ end
1207
1393
  obj = allocate
1208
1394
  obj.send(:initialize_struct,
1209
1395
  hash["id"],
@@ -1220,6 +1406,9 @@ module Presto::Client
1220
1406
  class << TopNRowNumberNode =
1221
1407
  Base.new(:id, :source, :partition_by, :order_by, :orderings, :row_number_symbol, :max_row_count_per_partition, :partial, :hash_symbol)
1222
1408
  def decode(hash)
1409
+ unless hash.is_a?(Hash)
1410
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1411
+ end
1223
1412
  obj = allocate
1224
1413
  obj.send(:initialize_struct,
1225
1414
  hash["id"],
@@ -1239,6 +1428,9 @@ module Presto::Client
1239
1428
  class << TypeParameterRequirement =
1240
1429
  Base.new(:name, :comparable_required, :orderable_required, :variadic_bound)
1241
1430
  def decode(hash)
1431
+ unless hash.is_a?(Hash)
1432
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1433
+ end
1242
1434
  obj = allocate
1243
1435
  obj.send(:initialize_struct,
1244
1436
  hash["name"],
@@ -1253,6 +1445,9 @@ module Presto::Client
1253
1445
  class << UnionNode =
1254
1446
  Base.new(:id, :sources, :symbol_mapping)
1255
1447
  def decode(hash)
1448
+ unless hash.is_a?(Hash)
1449
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1450
+ end
1256
1451
  obj = allocate
1257
1452
  obj.send(:initialize_struct,
1258
1453
  hash["id"],
@@ -1266,6 +1461,9 @@ module Presto::Client
1266
1461
  class << UnnestNode =
1267
1462
  Base.new(:id, :source, :replicate_symbols, :unnest_symbols, :ordinality_symbol)
1268
1463
  def decode(hash)
1464
+ unless hash.is_a?(Hash)
1465
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1466
+ end
1269
1467
  obj = allocate
1270
1468
  obj.send(:initialize_struct,
1271
1469
  hash["id"],
@@ -1281,6 +1479,9 @@ module Presto::Client
1281
1479
  class << ValuesNode =
1282
1480
  Base.new(:id, :output_symbols, :rows)
1283
1481
  def decode(hash)
1482
+ unless hash.is_a?(Hash)
1483
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1484
+ end
1284
1485
  obj = allocate
1285
1486
  obj.send(:initialize_struct,
1286
1487
  hash["id"],
@@ -1294,6 +1495,9 @@ module Presto::Client
1294
1495
  class << WindowNode =
1295
1496
  Base.new(:id, :source, :partition_by, :order_by, :orderings, :frame, :window_functions, :signatures, :hash_symbol, :pre_partitioned_inputs, :pre_sorted_order_prefix)
1296
1497
  def decode(hash)
1498
+ unless hash.is_a?(Hash)
1499
+ raise TypeError, "Can't convert #{hash.class} to Hash"
1500
+ end
1297
1501
  obj = allocate
1298
1502
  obj.send(:initialize_struct,
1299
1503
  hash["id"],
@@ -94,8 +94,9 @@ module Presto::Client
94
94
  private :init_request
95
95
 
96
96
  def post_query_request!
97
+ uri = "/v1/statement"
97
98
  response = @faraday.post do |req|
98
- req.url "/v1/statement"
99
+ req.url uri
99
100
 
100
101
  req.body = @query
101
102
  init_request(req)
@@ -107,8 +108,7 @@ module Presto::Client
107
108
  end
108
109
 
109
110
  body = response.body
110
- hash = MultiJson.load(body)
111
- @results = Models::QueryResults.decode(hash)
111
+ @results = load_json(uri, body, Models::QueryResults)
112
112
  end
113
113
 
114
114
  private :post_query_request!
@@ -152,16 +152,32 @@ module Presto::Client
152
152
  uri = @results.next_uri
153
153
 
154
154
  body = faraday_get_with_retry(uri)
155
- @results = Models::QueryResults.decode(MultiJson.load(body))
155
+ @results = load_json(uri, body, Models::QueryResults)
156
156
 
157
157
  return true
158
158
  end
159
159
 
160
160
  def query_info
161
- body = faraday_get_with_retry("/v1/query/#{@results.id}")
162
- Models::QueryInfo.decode(MultiJson.load(body))
161
+ uri = "/v1/query/#{@results.id}"
162
+ body = faraday_get_with_retry(uri)
163
+ load_json(uri, body, Models::QueryInfo)
163
164
  end
164
165
 
166
+ def load_json(uri, body, body_class)
167
+ hash = MultiJson.load(body)
168
+ begin
169
+ body_class.decode(hash)
170
+ rescue => e
171
+ if body.size > 1024 + 3
172
+ body = "#{body[0, 1024]}..."
173
+ end
174
+ @exception = PrestoHttpError.new(500, "Presto API returned unexpected structure at #{uri}. Expected #{body_class} but got #{body}: #{e}")
175
+ raise @exception
176
+ end
177
+ end
178
+
179
+ private :load_json
180
+
165
181
  def faraday_get_with_retry(uri, &block)
166
182
  start = Time.now
167
183
  attempts = 0
@@ -15,6 +15,6 @@
15
15
  #
16
16
  module Presto
17
17
  module Client
18
- VERSION = "0.4.14"
18
+ VERSION = "0.4.15"
19
19
  end
20
20
  end
data/modelgen/models.rb CHANGED
@@ -77,6 +77,9 @@ module Presto::Client
77
77
 
78
78
  module PlanNode
79
79
  def self.decode(hash)
80
+ unless hash.is_a?(Hash)
81
+ raise TypeError, "Can't convert #{hash.class} to Hash"
82
+ end
80
83
  model_class = case hash["@type"]
81
84
  when "output" then OutputNode
82
85
  when "project" then ProjectNode
@@ -122,6 +125,9 @@ module Presto::Client
122
125
  class << DistributionSnapshot =
123
126
  Base.new(:max_error, :count, :total, :p01, :p05, :p10, :p25, :p50, :p75, :p90, :p95, :p99, :min, :max)
124
127
  def decode(hash)
128
+ unless hash.is_a?(Hash)
129
+ raise TypeError, "Can't convert #{hash.class} to Hash"
130
+ end
125
131
  obj = allocate
126
132
  obj.send(:initialize_struct,
127
133
  hash["maxError"],
@@ -147,6 +153,9 @@ module Presto::Client
147
153
  class << EquiJoinClause =
148
154
  Base.new(:left, :right, :probe, :index)
149
155
  def decode(hash)
156
+ unless hash.is_a?(Hash)
157
+ raise TypeError, "Can't convert #{hash.class} to Hash"
158
+ end
150
159
  obj = allocate
151
160
  obj.send(:initialize_struct,
152
161
  hash["left"],
@@ -161,6 +170,9 @@ module Presto::Client
161
170
  class << WriterTarget =
162
171
  Base.new(:type, :handle)
163
172
  def decode(hash)
173
+ unless hash.is_a?(Hash)
174
+ raise TypeError, "Can't convert #{hash.class} to Hash"
175
+ end
164
176
  obj = allocate
165
177
  model_class = case hash["@type"]
166
178
  when "CreateHandle" then OutputTableHandle
@@ -178,6 +190,9 @@ module Presto::Client
178
190
  class << DeleteHandle =
179
191
  Base.new(:handle)
180
192
  def decode(hash)
193
+ unless hash.is_a?(Hash)
194
+ raise TypeError, "Can't convert #{hash.class} to Hash"
195
+ end
181
196
  obj = allocate
182
197
  obj.send(:initialize_struct,
183
198
  TableHandle.decode(hash['handle'])
@@ -191,6 +206,9 @@ module Presto::Client
191
206
  class << PageBufferInfo =
192
207
  Base.new(:partition, :buffered_pages, :queued_pages, :buffered_bytes, :pages_added)
193
208
  def decode(hash)
209
+ unless hash.is_a?(Hash)
210
+ raise TypeError, "Can't convert #{hash.class} to Hash"
211
+ end
194
212
  obj = allocate
195
213
  obj.send(:initialize_struct,
196
214
  hash["partition"],
@@ -159,6 +159,11 @@ module PrestoModels
159
159
 
160
160
  def format_decode
161
161
  puts_with_indent 1, "def decode(hash)"
162
+
163
+ puts_with_indent 2, "unless hash.is_a?(Hash)"
164
+ puts_with_indent 3, "raise TypeError, \"Can't convert \#{hash.class} to Hash\""
165
+ puts_with_indent 2, "end"
166
+
162
167
  if @special_struct_initialize_method
163
168
  puts_with_indent 2, "obj = allocate"
164
169
  puts_with_indent 2, "obj.send(:#{@special_struct_initialize_method},"
@@ -82,5 +82,24 @@ describe Presto::Client::StatementClient do
82
82
  retry_p.should be_true
83
83
  end
84
84
 
85
+ it "decodes DeleteHandle" do
86
+ dh = Models::DeleteHandle.decode({
87
+ "handle" => {
88
+ "connectorId" => "c1",
89
+ "connectorHandle" => {},
90
+ }
91
+ })
92
+ dh.handle.should be_a_kind_of Models::TableHandle
93
+ dh.handle.connector_id.should == "c1"
94
+ dh.handle.connector_handle.should == {}
95
+ end
96
+
97
+ it "validates models" do
98
+ lambda do
99
+ Models::DeleteHandle.decode({
100
+ "handle" => "invalid"
101
+ })
102
+ end.should raise_error(TypeError, /String to Hash/)
103
+ end
85
104
  end
86
105
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presto-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.14
4
+ version: 0.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-02 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.5.1
151
+ rubygems_version: 2.4.8
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Presto client library