OmniSciDB  c07336695a
MapDExample Class Reference

Static Public Member Functions

static void main (String[] args)
 
static MapD.Client get_client (String host_or_uri, int port, boolean http)
 

Detailed Description

Definition at line 64 of file MapDExample.java.

Member Function Documentation

◆ get_client()

static MapD.Client MapDExample.get_client ( String  host_or_uri,
int  port,
boolean  http 
)
inlinestatic

Definition at line 144 of file MapDExample.java.

References client.

Referenced by MapDExample.MapDExample.Main(), and main().

144  {
145  THttpClient httpTransport;
146  TTransport transport;
147  TBinaryProtocol protocol;
148  TJSONProtocol jsonProtocol;
149  TSocket socket;
150  MapD.Client client;
151 
152  try {
153  if (http) {
154  httpTransport = new THttpClient(host_or_uri);
155  jsonProtocol = new TJSONProtocol(httpTransport);
156  client = new MapD.Client(jsonProtocol);
157  httpTransport.open();
158  return client;
159  } else {
160  transport = new TSocket(host_or_uri, port);
161  protocol = new TBinaryProtocol(transport);
162  client = new MapD.Client(protocol);
163  transport.open();
164  return client;
165  }
166  } catch (TException x) {
167  x.printStackTrace();
168  }
169  return null;
170  }
mapd::shared_ptr< MapDClient > client
+ Here is the caller graph for this function:

◆ main()

static void MapDExample.main ( String []  args)
inlinestatic

Definition at line 65 of file MapDExample.java.

References anonymous_namespace{ExecuteTest.cpp}.c(), client, get_client(), anonymous_namespace{UpdateMetadataTest.cpp}.query, session, and Experimental.String.

65  {
66  String db_name = "mapd";
67  String user_name = "mapd";
68  String passwd = "HyperInteractive";
69  String hostname = "http://test.mapd.com:6274";
70  int portno = 6274;
71  MapD.Client client;
72  int session;
73  String query;
74  TQueryResult results;
75  int numRows, numCols;
76  boolean fieldIsArray;
77  TDatumType fieldType;
78  String fieldName, fieldType2;
79 
80  try {
81  client = get_client(hostname, portno, false);
82  session = client.connect(user_name, passwd, db_name);
83  System.out.println("Connection complete");
84  query = "select a,b from table1 limit 25;";
85  System.out.println("Query is: " + query);
86 
87  // always use True for is columnar
88  results = client.sql_execute(session, query, true, null, -1, -1);
89 
90  if (results.row_set.is_columnar) {
91  numRows = results.row_set.columns.get(0).nulls.size();
92  numCols = results.row_set.row_desc.size();
93  for (int r = 0; r < numRows; r++) {
94  for (int c = 0; c < numCols; c++) {
95  fieldName = results.row_set.row_desc.get(c).col_name;
96  fieldType = results.row_set.row_desc.get(c).col_type.type;
97  fieldType2 = fieldType.toString();
98  fieldIsArray = results.row_set.row_desc.get(c).col_type.is_array;
99  System.out.println(fieldName);
100  if (fieldIsArray) {
101  System.out.println(
102  results.row_set.columns.get(c).data.arr_col.get(r).data.str_col);
103  } else {
104  switch (fieldType2) {
105  case "BOOL":
106  break;
107  case "SMALLINT":
108  case "INT":
109  case "BIGINT":
110  System.out.println(results.row_set.columns.get(c).data.int_col.get(r));
111  break;
112  case "FLOAT":
113  case "DOUBLE":
114  case "DECIMAL":
115  System.out.println(results.row_set.columns.get(c).data.real_col.get(r));
116  break;
117  case "STR":
118  System.out.println(results.row_set.columns.get(c).data.str_col.get(r));
119  break;
120  case "TIME":
121  case "TIMESTAMP":
122  case "DATE":
123  System.out.println(new Date(
124  results.row_set.columns.get(c).data.int_col.get(r) * 1000));
125  break;
126  default:
127  break;
128  }
129  }
130  }
131  }
132 
133  } else {
134  System.out.println("Please use columns not row in query execution");
135  client.disconnect(session);
136  System.exit(0);
137  }
138  client.disconnect(session);
139  } catch (Exception x) {
140  x.printStackTrace();
141  }
142  }
void c(const std::string &query_string, const ExecutorDeviceType device_type)
mapd::shared_ptr< MapDClient > client
static MapD.Client get_client(String host_or_uri, int port, boolean http)
TSessionId session
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: