aboutsummaryrefslogtreecommitdiff
path: root/contrib/native/client/src/include/drill/drillClient.hpp
blob: 00ff723445f1ec97cff61152bc11aefb4587a7b2 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#ifndef DRILL_CLIENT_H
#define DRILL_CLIENT_H

#include <vector>
#include <boost/thread.hpp>
#include "drill/common.hpp"
#include "drill/collections.hpp"
#include "drill/protobuf/Types.pb.h"

namespace exec{
    namespace shared{
        class DrillPBError;
    };
};

namespace Drill{

//struct UserServerEndPoint;
class  DrillClientImplBase;
class  DrillClientImpl;
class  DrillClientQueryResult;
class  FieldMetadata;
class  PreparedStatement;
class  RecordBatch;
class  SchemaDef;

enum QueryType{
    SQL = 1,
    LOGICAL = 2,
    PHYSICAL = 3
};

class DECLSPEC_DRILL_CLIENT DrillClientError{
    public:
        static const uint32_t CONN_ERROR_START = 100;
        static const uint32_t QRY_ERROR_START =  200;

        DrillClientError(uint32_t s, uint32_t e, char* m){status=s; errnum=e; msg=m;};
        DrillClientError(uint32_t s, uint32_t e, std::string m){status=s; errnum=e; msg=m;};

        static DrillClientError*  getErrorObject(const exec::shared::DrillPBError& e);

        // To get the error number we add a error range start number to
        // the status code returned (either status_t or connectionStatus_t)
        uint32_t status; // could be either status_t or connectionStatus_t
        uint32_t errnum;
        std::string msg;
};

// Only one instance of this class exists. A static member of DrillClientImpl;
class DECLSPEC_DRILL_CLIENT DrillClientInitializer{
    public:
        DrillClientInitializer();
        ~DrillClientInitializer();
};

// Only one instance of this class exists. A static member of DrillClientImpl;
class DECLSPEC_DRILL_CLIENT DrillClientConfig{
    public:
        DrillClientConfig();
        ~DrillClientConfig();
        static void initLogging(const char* path);
        static void setLogLevel(logLevel_t l);
        static void setBufferLimit(uint64_t l);
        static uint64_t getBufferLimit();
        static void setSocketTimeout(int32_t l);
        static void setHandshakeTimeout(int32_t l);
        static void setQueryTimeout(int32_t l);
        static void setHeartbeatFrequency(int32_t l);
        static int32_t getSocketTimeout();
        static int32_t getHandshakeTimeout();
        static int32_t getQueryTimeout();
        static int32_t getHeartbeatFrequency();
        static logLevel_t getLogLevel();

        /**
         * Return the client name sent to the server when connecting
         *
         * @return the current client name
         */
        static const std::string& getClientName();

        /**
         * Set the client name to be sent to the server when connecting.
         *
         * Only new connections will use the new value. Existing connections
         * will be left unchanged.
         *
         * @param name the name to be send to the server
         */
        static void setClientName(const std::string& name);

        /**
         * Return the application name sent to the server when connecting
         *
         * @return the current application name
         */
        static const std::string& getApplicationName();

        /**
         * Set the application name to be sent to the server when connecting.
         *
         * Only new connections will use the new value. Existing connections
         * will be left unchanged.
         *
         * @param name the name to be send to the server
         */
        static void setApplicationName(const std::string& name);



    private:
        // The logging level
        static logLevel_t s_logLevel;
        // The total amount of memory to be allocated by an instance of DrillClient.
        // For future use. Currently, not enforced.
        static uint64_t s_bufferLimit;

        /**
         * DrillClient configures timeout (in seconds) in a fine granularity.
         * Disabled by setting the value to zero.
         *
         * s_socketTimout: (default 0)
         *      set SO_RCVTIMEO and SO_SNDTIMEO socket options and place a
         *		timeout on socket receives and sends. It is disabled by default.
         *
         * s_handshakeTimeout: (default 5)
         *      place a timeout on validating handshake. When an endpoint (host:port)
         *		is reachable but drillbit hangs or running another service. It will
         *		avoid the client hanging.
         *
         * s_queryTimeout: (default 180)
         *      place a timeout on waiting result of querying.
         *
         * s_heartbeatFrequency: (default 30)
         *      Seconds of idle activity after which a heartbeat is sent to the drillbit
         */
        static int32_t s_socketTimeout;
        static int32_t s_handshakeTimeout;
        static int32_t s_queryTimeout;
        static int32_t s_heartbeatFrequency;
        static boost::mutex s_mutex;

        // The client name (default to DRILL_CONNECTOR_NAME)
        static std::string s_clientName;
        // The application name (default to <empty>)
        static std::string s_applicationName;
};


class DECLSPEC_DRILL_CLIENT DrillUserProperties{
    public:
        static const std::map<std::string, uint32_t> USER_PROPERTIES;

        DrillUserProperties(){};

        void setProperty( const std::string& propName, const std::string& propValue){
            std::pair< std::string, std::string> in = make_pair(propName, propValue);
            m_properties.push_back(in);
        }

        size_t size() const { return m_properties.size(); }

        const std::string& keyAt(size_t i) const { return m_properties.at(i).first; }

        const std::string& valueAt(size_t i) const { return m_properties.at(i).second; }

        bool validate(std::string& err);

    private:
        std::vector< std::pair< std::string, std::string> > m_properties;
};

/*
 * Handle to the Query submitted for execution.
 * */
typedef void* QueryHandle_t;

/*
 * Query Results listener callback. This function is called for every record batch after it has
 * been received and decoded. The listener function should return a status.
 * If the listener returns failure, the query will be canceled.
 * The listener is also called one last time when the query is completed or gets an error. In that
 * case the RecordBatch Parameter is NULL. The DrillClientError parameter is NULL is there was no
 * error oterwise it will have a valid DrillClientError object.
 * DrillClientQueryResult will hold a listener & listener contxt for the call back function
 */
typedef status_t (*pfnQueryResultsListener)(QueryHandle_t ctx, RecordBatch* b, DrillClientError* err);

/*
 * The schema change listener callback. This function is called if the record batch detects a
 * change in the schema. The client application can call getColDefs in the RecordIterator or
 * get the field information from the RecordBatch itself and handle the change appropriately.
 */
typedef status_t (*pfnSchemaListener)(void* ctx, FieldDefPtr f, DrillClientError* err);

/**
 * The prepared statement creation listener
 *
 * This function is called when a prepared statement is created, or if an error occurs during the prepared statement creation.
 * This callback is only invoked once. 
 * @param[in] ctx the listener context provided to getColumns
 * @param[in] pstmt the prepared statement handle, NULL in case of error
 * @param[in] err an error object, NULL in case of success
 */
typedef status_t (*pfnPreparedStatementListener)(void* ctx, PreparedStatement* pstmt, DrillClientError* err);

/*
 * A Record Iterator instance is returned by the SubmitQuery class. Calls block until some data
 * is available, or until all data has been returned.
 */

class DECLSPEC_DRILL_CLIENT RecordIterator{
    friend class DrillClient;
    public:

    ~RecordIterator();
    /*
     * Returns a vector of column(i.e. field) definitions. The returned reference is guaranteed to be valid till the
     * end of the query or until a schema change event is received. If a schema change event is received by the
     * application, the application should discard the reference it currently holds and call this function again.
     */
    FieldDefPtr getColDefs();

    /* Move the current pointer to the next record. */
    status_t next();

    /* Gets the ith column in the current record. */
    status_t getCol(size_t i, void** b, size_t* sz);

    /* true if ith column in the current record is NULL */
    bool isNull(size_t i);

    /* Cancels the query. */
    status_t cancel();

    /*  Returns true is the schem has changed from the previous record. Returns false for the first record. */
    bool hasSchemaChanged();

    void registerSchemaChangeListener(pfnSchemaListener l);

    bool hasError();
    /*
     * Returns the last error message
     */
    const std::string& getError();

    private:
    RecordIterator(DrillClientQueryResult* pResult){
        this->m_currentRecord=-1;
        this->m_pCurrentRecordBatch=NULL;
        this->m_pQueryResult=pResult;
        //m_pColDefs=NULL;
    }

    DrillClientQueryResult* m_pQueryResult;
    size_t m_currentRecord;
    RecordBatch* m_pCurrentRecordBatch;
    boost::mutex m_recordBatchMutex;
    FieldDefPtr m_pColDefs; // Copy of the latest column defs made from the
    // first record batch with this definition
};

namespace meta {
  // Set of template functions to create bitmasks
  template<typename T>
  inline T
  operator&(T __a, T __b)
  { return T(static_cast<int>(__a) & static_cast<int>(__b)); }
  template<typename T>
  inline T
  operator|(T __a, T __b)
  { return T(static_cast<int>(__a) | static_cast<int>(__b)); }
  template<typename T>
  inline T
  operator^(T __a, T __b)
  { return T(static_cast<int>(__a) ^ static_cast<int>(__b)); }
  template<typename T>
  inline T&
  operator|=(T& __a, T __b)
  { return __a = __a | __b; }
  template<typename T>
  inline T&
  operator&=(T& __a, T __b)
  { return __a = __a & __b; }
  template<typename T>
  inline T&
  operator^=(T& __a, T __b)
  { return __a = __a ^ __b; }
  template<typename T>
  inline T
  operator~(T __a)
  { return T(~static_cast<int>(__a)); }

  /*
   * Internal type for Date/Time literals support
   */
  enum _DateTimeLiteralSupport {
    _DL_NONE                      = 0,
    _DL_DATE                      = 1 << 1L,
    _DL_TIME                      = 1 << 2L,
    _DL_TIMESTAMP                 = 1 << 3L,
    _DL_INTERVAL_YEAR             = 1 << 4L,
    _DL_INTERVAL_MONTH            = 1 << 5L,
    _DL_INTERVAL_DAY              = 1 << 6L,
    _DL_INTERVAL_HOUR             = 1 << 7L,
    _DL_INTERVAL_MINUTE           = 1 << 8L,
    _DL_INTERVAL_SECOND           = 1 << 9L,
    _DL_INTERVAL_YEAR_TO_MONTH    = 1 << 10L,
    _DL_INTERVAL_DAY_TO_HOUR      = 1 << 11L,
    _DL_INTERVAL_DAY_TO_MINUTE    = 1 << 12L,
    _DL_INTERVAL_DAY_TO_SECOND    = 1 << 13L,
    _DL_INTERVAL_HOUR_TO_MINUTE   = 1 << 14L,
    _DL_INTERVAL_HOUR_TO_SECOND   = 1 << 15L,
    _DL_INTERVAL_MINUTE_TO_SECOND = 1 << 16L
  };

  template inline _DateTimeLiteralSupport operator&(_DateTimeLiteralSupport __a, _DateTimeLiteralSupport __b);
  template inline _DateTimeLiteralSupport operator|(_DateTimeLiteralSupport __a, _DateTimeLiteralSupport __b);
  template inline _DateTimeLiteralSupport operator^(_DateTimeLiteralSupport __a, _DateTimeLiteralSupport __b);

  template inline _DateTimeLiteralSupport& operator&=(_DateTimeLiteralSupport& __a, _DateTimeLiteralSupport __b);
  template inline _DateTimeLiteralSupport& operator|=(_DateTimeLiteralSupport& __a, _DateTimeLiteralSupport __b);
  template inline _DateTimeLiteralSupport& operator^=(_DateTimeLiteralSupport& __a, _DateTimeLiteralSupport __b);

  template inline _DateTimeLiteralSupport operator~(_DateTimeLiteralSupport __a);

  /**
   * Date time literal support flags
   */
  typedef _DateTimeLiteralSupport DateTimeLiteralSupport;

  /** Does not support Date/Time literals */
  static const DateTimeLiteralSupport DL_NONE = _DL_NONE;
  /** Supports DATE literal */
  static const DateTimeLiteralSupport DL_DATE = _DL_DATE;
  /** Supports TIME literal */
  static const DateTimeLiteralSupport DL_TIME = _DL_TIME;
  /** Supports TIMESTAMP literal */
  static const DateTimeLiteralSupport DL_TIMESTAMP = _DL_TIMESTAMP;
  /** Supports INTERVAL YEAR literal */
  static const DateTimeLiteralSupport DL_INTERVAL_YEAR = _DL_INTERVAL_YEAR;
  /** Supports INTERVAL MONTH literal */
  static const DateTimeLiteralSupport DL_INTERVAL_MONTH = _DL_INTERVAL_MONTH;
  /** Supports INTERVAL DAY literal */
  static const DateTimeLiteralSupport DL_INTERVAL_DAY = _DL_INTERVAL_DAY;
  /** Supports INTERVAL HOUR literal */
  static const DateTimeLiteralSupport DL_INTERVAL_HOUR = _DL_INTERVAL_HOUR;
  /** Supports INTERVAL MINUTE literal */
  static const DateTimeLiteralSupport DL_INTERVAL_MINUTE = _DL_INTERVAL_MINUTE;
  /** Supports INTERVAL SECOND literal */
  static const DateTimeLiteralSupport DL_INTERVAL_SECOND = _DL_INTERVAL_SECOND;
  /** Supports INTERVAL YEAR TO MONTH literal */
  static const DateTimeLiteralSupport DL_INTERVAL_YEAR_TO_MONTH = _DL_INTERVAL_YEAR_TO_MONTH;
  /** Supports INTERVAL DAY TO HOUR literal */
  static const DateTimeLiteralSupport DL_INTERVAL_DAY_TO_HOUR = _DL_INTERVAL_DAY_TO_HOUR;
  /** Supports INTERVAL DAY TO MINUTE literal */
  static const DateTimeLiteralSupport DL_INTERVAL_DAY_TO_MINUTE = _DL_INTERVAL_DAY_TO_MINUTE;
  /** Supports INTERVAL DAY TO SECOND literal */
  static const DateTimeLiteralSupport DL_INTERVAL_DAY_TO_SECOND = _DL_INTERVAL_DAY_TO_SECOND;
  /** Supports INTERVAL HOUR TO MINUTE literal */
  static const DateTimeLiteralSupport DL_INTERVAL_HOUR_TO_MINUTE = _DL_INTERVAL_HOUR_TO_MINUTE;
  /** Supports INTERVAL HOUR TO SECOND literal */
  static const DateTimeLiteralSupport DL_INTERVAL_HOUR_TO_SECOND = _DL_INTERVAL_HOUR_TO_SECOND;
  /** Supports INTERVAL MINUTE TO SECOND literal */
  static const DateTimeLiteralSupport DL_INTERVAL_MINUTE_TO_SECOND = _DL_INTERVAL_MINUTE_TO_SECOND;

  /*
   * Internal type for COLLATE support
   */
  enum _CollateSupport {
      _C_NONE       = 0,
      _C_GROUPBY    = 1 << 1L
  };

  template inline _CollateSupport operator&(_CollateSupport __a, _CollateSupport __b);
  template inline _CollateSupport operator|(_CollateSupport __a, _CollateSupport __b);
  template inline _CollateSupport operator^(_CollateSupport __a, _CollateSupport __b);

  template inline _CollateSupport& operator&=(_CollateSupport& __a, _CollateSupport __b);
  template inline _CollateSupport& operator|=(_CollateSupport& __a, _CollateSupport __b);
  template inline _CollateSupport& operator^=(_CollateSupport& __a, _CollateSupport __b);

  template inline _CollateSupport operator~(_CollateSupport __a);


  /**
   * COLLATE support flags
   */
  typedef _CollateSupport CollateSupport;
  static const CollateSupport C_NONE = _C_NONE;       /**< COLLATE clauses are not supported */
  static const CollateSupport C_GROUPBY = _C_GROUPBY; /**< a COLLATE clause can be added after each grouping column */

  /**
   * Correlation names support flags
   */
  enum CorrelationNamesSupport {
    CN_NONE            = 1, /**< Correlation names are not supported */
    CN_DIFFERENT_NAMES = 2, /**< Correlation names are supported, but names have to be different
    							 from the tables they represent */
    CN_ANY_NAMES       = 3  /**< Correlation names are supported with no restriction on names */
  };

  /**
   * Group by support
   */
  enum GroupBySupport {
      GB_NONE,         /**< Do not support GROUP BY */
      GB_SELECT_ONLY,  /**< Only support GROUP BY clause with non aggregated columns in the select list */
      GB_BEYOND_SELECT,/**< Support GROUP BY clauses with columns absent from the select list
      	  	  	  	  	    if all the non-aggregated column from the select list are also added. */
      GB_UNRELATED     /** Support GROUP BY clauses with columns absent from the select list */
  };

  /**
   * Identified case support
   */
  enum IdentifierCase {
      IC_STORES_LOWER,  /**< Mixed case unquoted SQL identifier are treated as
	  	  	  	  	  	    case insensitive and stored in lower case */
      IC_STORES_MIXED,  /**< Mixed case unquoted SQL identifier are treated as
	  	  	  	  	  	    case insensitive and stored in mixed case */
      IC_STORES_UPPER,  /**< Mixed case unquoted SQL identifier are treated as
	  	  	  	  	  	    case insensitive and stored in upper case */
      IC_SUPPORTS_MIXED /**< Mixed case unquoted SQL identifier are treated as
	  	  	  	  	  	    case sensitive and stored in mixed case */
  };

  /**
   * Null collation support
   */
  enum NullCollation {
      NC_AT_START,/**< NULL values are sorted at the start regardless of the order*/
      NC_AT_END,  /**< NULL values are sorted at the end regardless of the order*/
      NC_HIGH,    /**< NULL is the highest value */
      NC_LOW      /**< NULL is the lowest value */
  };


  /*
   * Internal type for Outer join support flags
   */
  enum _OuterJoinSupport {
      _OJ_NONE                  = 0,      //!< _OJ_NONE
      _OJ_LEFT                  = 1 << 1L,//!< _OJ_LEFT
      _OJ_RIGHT                 = 1 << 2L,//!< _OJ_RIGHT
      _OJ_FULL                  = 1 << 3L,//!< _OJ_FULL
      _OJ_NESTED                = 1 << 4L,//!< _OJ_NESTED
      _OJ_NOT_ORDERED           = 1 << 5L,//!< _OJ_NOT_ORDERED
      _OJ_INNER                 = 1 << 6L,//!< _OJ_INNER
      _OJ_ALL_COMPARISON_OPS    = 1 << 7L //!< _OJ_ALL_COMPARISON_OPS
  };

  template inline _OuterJoinSupport operator&(_OuterJoinSupport __a, _OuterJoinSupport __b);
  template inline _OuterJoinSupport operator|(_OuterJoinSupport __a, _OuterJoinSupport __b);
  template inline _OuterJoinSupport operator^(_OuterJoinSupport __a, _OuterJoinSupport __b);

  template inline _OuterJoinSupport& operator&=(_OuterJoinSupport& __a, _OuterJoinSupport __b);
  template inline _OuterJoinSupport& operator|=(_OuterJoinSupport& __a, _OuterJoinSupport __b);
  template inline _OuterJoinSupport& operator^=(_OuterJoinSupport& __a, _OuterJoinSupport __b);

  template inline _OuterJoinSupport operator~(_OuterJoinSupport __a);

  /**
   * Outer join support flags
   */
  typedef _OuterJoinSupport OuterJoinSupport;
  /** Outer join is not supported */
  static const OuterJoinSupport OJ_NONE                 = _OJ_NONE;
  /** Left outer join is supported */
  static const OuterJoinSupport OJ_LEFT                 = _OJ_LEFT;
  /** Right outer join is supported */
  static const OuterJoinSupport OJ_RIGHT                = _OJ_RIGHT;
  /** Full outer join is supported */
  static const OuterJoinSupport OJ_FULL                 = _OJ_FULL;
  /** Nested outer join is supported */
  static const OuterJoinSupport OJ_NESTED               = _OJ_NESTED;
  /**
   * The columns names in the ON clause of a outer join don't have to share the same
   * order as their respective table names in the OUTER JOIN clause
   */
  static const OuterJoinSupport OJ_NOT_ORDERED          = _OJ_NOT_ORDERED;
  /**
   * The inner table can also be used in an inner join
   */
  static const OuterJoinSupport OJ_INNER                = _OJ_INNER;
  /**
   * Any comparison operator in supported in the ON clause.
   */
  static const OuterJoinSupport OJ_ALL_COMPARISON_OPS   = _OJ_ALL_COMPARISON_OPS;

  /**
   * Quoted Identified case support
   */
  enum QuotedIdentifierCase {
      QIC_STORES_LOWER,  /**< Mixed case quoted SQL identifier are treated as
	  	  	  	  	  	    case insensitive and stored in lower case */
      QIC_STORES_MIXED,  /**< Mixed case quoted SQL identifier are treated as
	  	  	  	  	  	    case insensitive and stored in mixed case */
      QIC_STORES_UPPER,  /**< Mixed case quoted SQL identifier are treated as
	  	  	  	  	  	    case insensitive and stored in upper case */
      QIC_SUPPORTS_MIXED /**< Mixed case quoted SQL identifier are treated as
	  	  	  	  	  	    case sensitive and stored in mixed case */
  };

  /*
   * Internal Subquery support flags type
   */
  enum _SubQuerySupport {
      _SQ_NONE          = 0,
      _SQ_CORRELATED    = 1 << 1L,
      _SQ_IN_COMPARISON = 1 << 2L,
      _SQ_IN_EXISTS     = 1 << 3L,
      _SQ_IN_INSERT     = 1 << 4L,
      _SQ_IN_QUANTIFIED = 1 << 5L
  };

  template inline _SubQuerySupport operator&(_SubQuerySupport __a, _SubQuerySupport __b);
  template inline _SubQuerySupport operator|(_SubQuerySupport __a, _SubQuerySupport __b);
  template inline _SubQuerySupport operator^(_SubQuerySupport __a, _SubQuerySupport __b);

  template inline _SubQuerySupport& operator&=(_SubQuerySupport& __a, _SubQuerySupport __b);
  template inline _SubQuerySupport& operator|=(_SubQuerySupport& __a, _SubQuerySupport __b);
  template inline _SubQuerySupport& operator^=(_SubQuerySupport& __a, _SubQuerySupport __b);

  template inline _SubQuerySupport operator~(_SubQuerySupport __a);

  /**
   * SubQuery support flags
   */
  typedef _SubQuerySupport SubQuerySupport;
  /**
   * Subqueries are not supported
   */
  static const SubQuerySupport SQ_NONE             = _SQ_NONE;
  /** Correlated subqueries are supported */
  static const SubQuerySupport SQ_CORRELATED       = _SQ_CORRELATED;
  /** Subqueries in comparison expressions are supported */
  static const SubQuerySupport SQ_IN_COMPARISON    = _SQ_IN_COMPARISON;
  /** Subqueries in EXISTS expressions are supported */
  static const SubQuerySupport SQ_IN_EXISTS        = _SQ_IN_EXISTS;
  /** Subqueries in INSERT expressions are supported */
  static const SubQuerySupport SQ_IN_INSERT        = _SQ_IN_INSERT;
  /** Subqueries in quantified expressions are supported */
  static const SubQuerySupport SQ_IN_QUANTIFIED    = _SQ_IN_QUANTIFIED;

  /*
   * Internal Union support flags type
   */
  enum _UnionSupport {
      _U_NONE       = 0,      //!< _U_NONE
      _U_UNION      = 1 << 1L,//!< _U_UNION
      _U_UNION_ALL  = 1 << 2L //!< _U_UNION_ALL
  };

  template inline _UnionSupport operator&(_UnionSupport __a, _UnionSupport __b);
  template inline _UnionSupport operator|(_UnionSupport __a, _UnionSupport __b);
  template inline _UnionSupport operator^(_UnionSupport __a, _UnionSupport __b);

  template inline _UnionSupport& operator&=(_UnionSupport& __a, _UnionSupport __b);
  template inline _UnionSupport& operator|=(_UnionSupport& __a, _UnionSupport __b);
  template inline _UnionSupport& operator^=(_UnionSupport& __a, _UnionSupport __b);

  template inline _UnionSupport operator~(_UnionSupport __a);

  /**
   * Union support flags
   */
  typedef _UnionSupport UnionSupport;
  /** Union is not supported */
  static const UnionSupport U_NONE       = _U_NONE;
  /** UNION is supported */
  static const UnionSupport U_UNION      = _U_UNION;
  /** UNION ALL is supported */
  static const UnionSupport U_UNION_ALL  = _U_UNION_ALL;

  class DECLSPEC_DRILL_CLIENT CatalogMetadata {
      protected:
      CatalogMetadata() {};
      public:
      virtual ~CatalogMetadata() {};

      virtual bool               hasCatalogName() const = 0;
      virtual const std::string& getCatalogName() const = 0;

      virtual bool               hasDescription() const = 0;
      virtual const std::string& getDescription() const = 0;

      virtual bool               hasConnect() const = 0;
      virtual const std::string& getConnect() const = 0;
  };

  class DECLSPEC_DRILL_CLIENT SchemaMetadata {
      protected:
      SchemaMetadata() {};

      public:
      virtual ~SchemaMetadata() {};

      virtual bool               hasCatalogName() const = 0;
      virtual const std::string& getCatalogName() const = 0;

      virtual bool               hasSchemaName() const = 0;
      virtual const std::string& getSchemaName() const = 0;

      virtual bool               hasOwnerName() const = 0;
      virtual const std::string& getOwner() const = 0;

      virtual bool               hasType() const = 0;
      virtual const std::string& getType() const = 0;

      virtual bool               hasMutable() const = 0;
      virtual const std::string& getMutable() const = 0;
  };

  class DECLSPEC_DRILL_CLIENT TableMetadata {
      protected:
      TableMetadata() {};

      public:
      virtual ~TableMetadata() {};

      virtual bool               hasCatalogName() const = 0;
      virtual const std::string& getCatalogName() const = 0;

      virtual bool               hasSchemaName() const = 0;
      virtual const std::string& getSchemaName() const = 0;

      virtual bool               hasTableName() const = 0;
      virtual const std::string& getTableName() const = 0;

      virtual bool               hasType() const = 0;
      virtual const std::string& getType() const = 0;
  };

  class DECLSPEC_DRILL_CLIENT ColumnMetadata {
      protected:
      ColumnMetadata() {};

      public:
      virtual ~ColumnMetadata() {};

      virtual bool               hasCatalogName() const = 0;
      virtual const std::string& getCatalogName() const = 0;

      virtual bool               hasSchemaName() const = 0;
      virtual const std::string& getSchemaName() const = 0;

      virtual bool               hasTableName() const = 0;
      virtual const std::string& getTableName() const = 0;

      virtual bool               hasColumnName() const = 0;
      virtual const std::string& getColumnName() const = 0;

      virtual bool               hasOrdinalPosition() const = 0;
      virtual std::size_t        getOrdinalPosition() const = 0;

      virtual bool               hasDefaultValue() const = 0;
      virtual const std::string& getDefaultValue() const = 0;

      virtual bool               hasNullable() const = 0;
      virtual bool               isNullable() const = 0;

      virtual bool               hasDataType() const = 0;
      virtual const std::string& getDataType() const = 0;

      virtual bool               hasColumnSize() const = 0;
      virtual std::size_t        getColumnSize() const = 0;

      virtual bool               hasCharMaxLength() const = 0;
      virtual std::size_t        getCharMaxLength() const = 0;

      virtual bool               hasCharOctetLength() const = 0;
      virtual std::size_t        getCharOctetLength() const = 0;

      virtual bool               hasNumericPrecision() const = 0;
      virtual int32_t            getNumericPrecision() const = 0;

      virtual bool               hasNumericRadix() const = 0;
      virtual int32_t            getNumericRadix() const = 0;

      virtual bool               hasNumericScale() const = 0;
      virtual int32_t            getNumericScale() const = 0;

      virtual bool               hasIntervalType() const = 0;
      virtual const std::string& getIntervalType() const = 0;

      virtual bool               hasIntervalPrecision() const = 0;
      virtual int32_t            getIntervalPrecision() const = 0;
  };
}

class DECLSPEC_DRILL_CLIENT Metadata {
  public:
    virtual ~Metadata() {};

    /**
     * Returns the connector name
     *
     * @return the connector name
     */
    virtual const std::string& getConnectorName() const = 0;

    /**
     * Returns the connector version string
     *
     * @return the connector version string
     */
    virtual const std::string& getConnectorVersion() const = 0;

    /**
     * Returns the connector major version
     *
     * @return the connector major version
     */
    virtual uint32_t getConnectorMajorVersion() const = 0;

    /**
     * Returns the connector minor version
     *
     * @return the connector minor version
     */
    virtual uint32_t getConnectorMinorVersion() const = 0;

    /**
     * Returns the connector patch version
     *
     * @return the connector patch version
     */
    virtual uint32_t getConnectorPatchVersion() const = 0;

    /**
     * Returns the server name
     *
     * @return the server name
     */
    virtual const std::string& getServerName() const = 0;

    /**
     * Returns the server version string
     *
     * @return the server version string
     */
    virtual const std::string& getServerVersion() const = 0;

    /**
     * Returns the server major version
     *
     * @return the server major version
     */
    virtual uint32_t getServerMajorVersion() const = 0;

    /**
     * Returns the server minor version
     *
     * @return the server minor version
     */
    virtual uint32_t getServerMinorVersion() const = 0;

    /**
     * Returns the server patch version
     *
     * @return the server patch version
     */
    virtual uint32_t getServerPatchVersion() const = 0;

    /**
     * Callback function invoked by getCatalogs when receiving results
     *
     * This callback is only invoked once. 
     * @param[in] ctx the listener context provided to getCatalogs
     * @param[in] metadata the catalog metadata, or NULL in case of error
     * @param[in] err an error object, NULL in case of success
     */
    typedef status_t (*pfnCatalogMetadataListener)(void* ctx, const DrillCollection<meta::CatalogMetadata>* metadata, DrillClientError* err);

    /**
     * Get a list of catalogPattern available to the current connection.
     * Only catalogs matching the catalogPattern LIKE expression are returned.
     *
     * @param[in] catalogPattern a catalog pattern
     * @param[in] listener a metadata listener
     * @param[in] context to be passed to the listener
     * @param[out] the query handle
     */
    virtual status_t getCatalogs(const std::string& catalogPattern, pfnCatalogMetadataListener listener, void* listenerCtx, QueryHandle_t* qHandle) = 0;

    /**
     * Callback function invoked by getSchemas when receiving results
     *
     * This callback is only invoked once. 
     * @param[in] ctx the listener context provided to getSchemas
     * @param[in] metadata the schema metadata, or NULL in case of error
     * @param[in] err an error object, NULL in case of success
     */
    typedef status_t (*pfnSchemaMetadataListener)(void* ctx, const DrillCollection<meta::SchemaMetadata>* metadata, DrillClientError* err);

    /**
     * Get a list of schemas available to the current connection.
     * Only schemas matching the catalogPattern and schemaPattern LIKE expressions are returned.
     *
     * @param[in] catalogPattern a catalog pattern
     * @param[in] schemaPattern a schema pattern
     * @param[in] listener a metadata query listener
     * @param[in] context to be passed to the listener
     * @param[out] the query handle
     */
    virtual status_t getSchemas(const std::string& catalogPattern, const std::string& schemaPattern, pfnSchemaMetadataListener listener, void* listenerCtx, QueryHandle_t* qHandle) = 0;

    /**
     * Callback function invoked by getTables when receiving results
     *
     * This callback is only invoked once. 
     * @param[in] ctx the listener context provided to getTables
     * @param[in] metadata the table metadata, or NULL in case of error
     * @param[in] err an error object, NULL in case of success
     */
    typedef status_t (*pfnTableMetadataListener)(void* ctx, const DrillCollection<meta::TableMetadata>* metadata, DrillClientError* err);

    /**
     * Get a list of tables available to the current connection.
     * Only tables matching the catalogPattern, schemaPattern and tablePattern LIKE expressions are returned.
     *
     * @param[in] catalogPattern a catalog pattern
     * @param[in] schemaPattern a schema pattern
     * @param[in] tablePattern a table pattern
     * @param[in] tableTypes a list of table types to look for. Pass NULL to not filter
     * @param[in] listener a metadata query listener
     * @param[in] context to be passed to the listener
     * @param[out] the query handle
     */
    virtual status_t getTables(const std::string& catalogPattern, const std::string& schemaPattern, const std::string& tablePattern, const std::vector<std::string>* tableTypes, 
                               pfnTableMetadataListener listener, void* listenerCtx, QueryHandle_t* qHandle) = 0;

    /**
     * Callback function invoked by getColumns when receiving results
     *
     * This callback is only invoked once. 
     * @param[in] ctx the listener context provided to getColumns
     * @param[in] metadata the columns metadata, or NULL in case of error
     * @param[in] err an error object, NULL in case of success
     */
    typedef status_t (*pfnColumnMetadataListener)(void* ctx, const DrillCollection<meta::ColumnMetadata>* metadata, DrillClientError* err);

    /**
     * Get a list of columns available to the current connection.
     * Only columns matching the catalogPattern, schemaPattern, tablePattern and columnPattern LIKE expressions are returned.
     *
     * @param[in] catalogPattern a catalog pattern
     * @param[in] schemaPattern a schema pattern
     * @param[in] tablePattern a table pattern
     * @param[in] columnPattern a colum name pattern
     * @param[in] listener a metadata query listener
     * @param[in] context to be passed to the listener
     * @param[out] the query handle
     */
    virtual status_t getColumns(const std::string& catalogPattern, const std::string& schemaPattern, const std:: string& tablePattern, const std::string& columnPattern, pfnColumnMetadataListener listener, void* listenerCtx, QueryHandle_t* qHandle) = 0;

    // Capabilities
    /**
     * Return if the current user can use all tables returned by the getTables method
     *
     * @result true if the user can select any table, false otherwise
     */
    virtual bool areAllTableSelectable() const = 0;

    /**
     * Return if the catalog name is at the start of a fully qualified table name
     *
     * @return true if the catalog name is at the start, false otherwise.
     */
    virtual bool isCatalogAtStart() const = 0;

    /**
     * Return the string used as a separator between the catalog and the table name
     *
     * @return the catalog separator
     */
    virtual const std::string& getCatalogSeparator() const = 0;

    /**
     * Return the term used by the server to designate a catalog
     *
     * @return the catalog term
     */
    virtual const std::string& getCatalogTerm() const = 0;

    /**
     * Return if the server supports column aliasing
     *
     * @return true if the server supports column aliasing, false otherwise
     */
    virtual bool isColumnAliasingSupported() const = 0;

    /**
     * Return if the result of a NULL and a non-NULL values concatenation is NULL
     *
     * @return true if the result is NULL, false otherwise
     */
    virtual bool isNullPlusNonNullNull() const = 0;

    /**
     * Return if the CONVERT function supports conversion for the given types
     *
     * @return true if the conversion is supported, false otherwise
     */
    virtual bool isConvertSupported(common::MinorType from, common::MinorType to) const = 0;

    /**
     * Return what kind of correlation name support the server provides
     *
     * @return the correlation name supported by the server
     */
    virtual meta::CorrelationNamesSupport getCorrelationNames() const = 0;

    /**
     * Returns if the connection to the server is read-only
     *
     * @return true if the connection is read-only, false otherwise
     */
    virtual bool isReadOnly() const = 0;

    /**
     * Return what kind of date time literals the server supports
     *
     * @return a bitmask of supported date/time literals
     */
    virtual meta::DateTimeLiteralSupport getDateTimeLiteralsSupport() const = 0;

    /**
     * Return what kind of COLLATE expressions are supported
     */
    virtual meta::CollateSupport getCollateSupport() const = 0;

    /**
     * Return what kind of GROUP BY support the server provides
     *
     * @return the group by support
     */
    virtual meta::GroupBySupport getGroupBySupport() const = 0;

    /**
     * Returns how unquoted identifier are stored
     *
     * @return the unquoted identifier storage policy
     */
    virtual meta::IdentifierCase getIdentifierCase() const = 0;

    /**
     * Returns the string used to quote SQL identifiers
     *
     * @return the quote string
     */
    virtual const std::string& getIdentifierQuoteString() const = 0;

    /**
     * Returns the list of SQL keywords supported by the database
     *
     * @return a list of keywords
     */
    virtual const std::vector<std::string>& getSQLKeywords() const = 0;

    /**
     * Returns if LIKE operator supports an escape clause
     *
     * @return true if escape claused are supported
     */
    virtual bool isLikeEscapeClauseSupported() const = 0;

    /**
     * Returns the maximum number of hexa characters supported for binary literals
     *
     * @return the length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxBinaryLiteralLength() const = 0;

    /**
     * Returns the maximum length of catalog names
     *
     * @return the length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxCatalogNameLength() const = 0;

    /**
     * Returns the maximum number of characters for string literals
     *
     * @return the length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxCharLiteralLength() const = 0;

    /**
     * Returns the maximum length of column names
     *
     * @return the length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxColumnNameLength() const = 0;

    /**
     * Returns the maximum number of columns in GROUP BY expressions
     *
     * @return the maximum number, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxColumnsInGroupBy() const = 0;

    /**
     * Returns the maximum number of columns in ORDER BY expressions
     *
     * @return the maximum number, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxColumnsInOrderBy() const = 0;

    /**
     * Returns the maximum number of columns in a SELECT list
     *
     * @return the maximum number, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxColumnsInSelect() const = 0;

    /**
     * Returns the maximum length for cursor names
     *
     * @return the maximum length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxCursorNameLength() const = 0;

    /**
     * Returns the maximum logical size for LOB types
     *
     * @return the maximum size, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxLogicalLobSize() const = 0;

    /**
     * Returns the maximum number of statements
     *
     * @return the maximum number, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxStatements() const = 0;

    /**
     * Returns the maximum number of bytes for a single row
     * @return the maximum size, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxRowSize() const = 0;

    /**
     * Returns if BLOB types are included in the maximum row size
     *
     * @return true if BLOB are included
     */
    virtual bool isBlobIncludedInMaxRowSize() const = 0;

    /**
     * Returns the maximum length for schema names
     * @return the maximum length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxSchemaNameLength() const = 0;

    /**
     * Returns the maximum length for statements
     * @return the maximum length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxStatementLength() const = 0;

    /**
     * Returns the maximum length for table names
     * @return the maximum length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxTableNameLength() const = 0;

    /**
     * Returns the maximum number of tables in a SELECT expression
     * @return the maximum number, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxTablesInSelect() const = 0;

    /**
     * Returns the maximum length for user names
     * @return the maximum length, 0 if unlimited or unknown
     */
    virtual std::size_t getMaxUserNameLength() const = 0;

    /**
     * Returns how NULL are sorted
     *
     * @return the NULL collation policy
     */
    virtual meta::NullCollation getNullCollation() const = 0;

    /**
     * Returns the list of supported numeric functions
     * @return a list of function names
     */
    virtual const std::vector<std::string>& getNumericFunctions() const = 0;

    /**
     * Returns how outer joins are supported
     * @return outer join support (as flags)
     */
    virtual meta::OuterJoinSupport getOuterJoinSupport() const = 0;

    /**
     * Returns if columns not in the SELECT column lists can be used
     * in the ORDER BY expression
     *
     * @return true if unrelated columns are supported in ORDER BY
     */
    virtual bool isUnrelatedColumnsInOrderBySupported() const = 0;

    /**
     * Returns how quoted identifier are stored
     *
     * @return the quoted identifier storage policy
     */
    virtual meta::QuotedIdentifierCase getQuotedIdentifierCase() const = 0;

    /**
     * Returns the term used to designate schemas
     *
     * @return the term
     */
    virtual const std::string& getSchemaTerm() const = 0;

    /**
     * Return the string for escaping patterns in metadata queries
     *
     * @return the characters for escaping, empty if not supported
     */
    virtual const std::string& getSearchEscapeString() const = 0;

    /**
     * Returns the list of extra characters that can be used in identifier names
     *
     * Extra characters are those characters beyond a-z, A-Z, 0-9 and '_' (underscore)
     *
     * @return a list of characters
     */
    virtual const std::string& getSpecialCharacters() const = 0;

    /**
     * Returns the list of supported string functions
     *
     * @return a list of function names
     */
    virtual const std::vector<std::string>& getStringFunctions() const = 0;

    /**
     * Returns how subqueries are supported
     *
     * @return the subqueries support (as flags)
     */
    virtual meta::SubQuerySupport getSubQuerySupport() const = 0;

    /**
     * Returns the list of supported system functions
     *
     * @return a list of function names
     */
    virtual const std::vector<std::string>& getSystemFunctions() const = 0;

    /**
     * Returns the term used to designate tables
     *
     * @return the term
     */
    virtual const std::string& getTableTerm() const = 0;

    /**
     * Returns the list of supported date/time functions
     *
     * @return a list of function names
     */
    virtual const std::vector<std::string>& getDateTimeFunctions() const = 0;

    /**
     * Returns if transactions are supported
     * @return true if transactions are supported
     */
    virtual bool isTransactionSupported() const = 0;

    /**
     * Returns how unions are supported
     *
     * @return the union support (as flags)
     */
    virtual meta::UnionSupport getUnionSupport() const = 0;

    /**
     * Returns if SELECT FOR UPDATE expressions are supported
     *
     * @return true if SELECT FOR UPDATE is supported
     */
    virtual bool isSelectForUpdateSupported() const = 0;
};

class DECLSPEC_DRILL_CLIENT DrillClient{
    public:
        /*
         * Get the application context from query handle
         */
        static void* getApplicationContext(QueryHandle_t handle);

        /*
         * Get the query status from query handle
         */
        static status_t getQueryStatus(QueryHandle_t handle);


        DrillClient();
        ~DrillClient();

        // change the logging level
        static void initLogging(const char* path, logLevel_t l);

        /**
         * Connect the client to a Drillbit using connection string and default schema.
         *
         * @param[in] connectStr: connection string
         * @param[in] defaultSchema: default schema (set to NULL and ignore it
         * if not specified)
         * @return    connection status
         */
        DEPRECATED connectionStatus_t connect(const char* connectStr, const char* defaultSchema=NULL);

        /*
         * Connect the client to a Drillbit using connection string and a set of user properties.
         * The connection string format can be found in comments of
         * [DRILL-780](https://issues.apache.org/jira/browse/DRILL-780)
         *
         * To connect via zookeeper, use the format:
         * "zk=zk1:port[,zk2:p2,...][/<path_to_drill_root>/<cluster_id>]".
         *
         * e.g.
         * ```
         * zk=localhost:2181
         * zk=localhost:2181/drill/drillbits1
         * zk=localhost:2181,zk2:2181/drill/drillbits1
         * ```
         *
         * To connect directly to a drillbit, use the format "local=host:port".
         *
         * e.g.
         * ```
         * local=127.0.0.1:31010
         * ```
         *
         * User properties is a set of name value pairs. The following properties are recognized:
         *     schema
         *     userName
         *     password
         *     useSSL [true|false]
         *     pemLocation
         *     pemFile
         *     (see drill/common.hpp for friendly defines and the latest list of supported proeprties)
         *
         * @param[in] connectStr: connection string
         * @param[in] properties
         * if not specified)
         * @return    connection status
         */
        connectionStatus_t connect(const char* connectStr, DrillUserProperties* properties);

        /* test whether the client is active */
        bool isActive();

        /*  close the connection. cancel any pending requests. */
        void close() ;

        /*
         * Submit a query asynchronously and wait for results to be returned through a callback. A query context handle is passed
         * back. The listener callback will return the handle in the ctx parameter.
         */
        status_t submitQuery(Drill::QueryType t, const std::string& plan, pfnQueryResultsListener listener, void* listenerCtx, QueryHandle_t* qHandle);

        /*
         * Submit a query asynchronously and wait for results to be returned through an iterator that returns
         * results synchronously. The client app needs to call freeQueryIterator on the iterator when done.
         */
        RecordIterator* submitQuery(Drill::QueryType t, const std::string& plan, DrillClientError* err);

        /**
         * Prepare a query.
         *
         * @param[in] sql the query to prepare
         * @param[in] listener a callback to be notified when the prepared statement is created, or if an error occured
         * @param[in] user context to provide to the callback
         * @param[out] a handle on the query
         */
        status_t prepareQuery(const std::string& sql, pfnPreparedStatementListener listener, void* listenerCtx, QueryHandle_t* qHandle);

        /*
         * Execute a prepared statement.
         *
         * @param[in] pstmt the prepared statement to execute
         * @param[in] listener a callback to be notified when results have arrived, or if an error occured
         * @param[in] user context to provide to the callback
         * @param[out] a handle on the query
         */
        status_t executeQuery(const PreparedStatement& pstmt, pfnQueryResultsListener listener, void* listenerCtx, QueryHandle_t* qHandle);

        /*
         * Cancel a query.
         *
         * @param[in] the handle of the query to cancel
         */
        void cancelQuery(QueryHandle_t handle);

        /*
         * The client application should call this function to wait for results if it has registered a
         * listener.
         */
        void waitForResults();

        /*
         * Returns the last error message
         */
        std::string& getError();

        /*
         * Returns the error message associated with the query handle
         */
        const std::string& getError(QueryHandle_t handle);
        /*
         * Applications using the async query submit method can register a listener for schema changes
         *
         */
        void registerSchemaChangeListener(QueryHandle_t* handle, pfnSchemaListener l);

        /*
         * Applications using the async query submit method should call freeQueryResources to free up resources
         * once the query is no longer being processed.
         */
        void freeQueryResources(QueryHandle_t* handle);

        /*
         * Applications using the sync query submit method should call freeQueryIterator to free up resources
         * once the RecordIterator is no longer being processed.
         */
        void freeQueryIterator(RecordIterator** pIter){ delete *pIter; *pIter=NULL;}

        /*
         * Applications using the async query submit method should call freeRecordBatch to free up resources
         * once the RecordBatch is processed and no longer needed.
         */
        void freeRecordBatch(RecordBatch* pRecordBatch);

        /**
         * Get access to the server metadata
         */
        Metadata* getMetadata();

        /**
         * Free resources associated with the metadata object
         */
        void freeMetadata(Metadata** metadata);

    private:
        static DrillClientInitializer s_init;
        static DrillClientConfig s_config;

        DrillClientImplBase * m_pImpl;
};

} // namespace Drill

#endif