@@ -40,8 +40,8 @@ void insertRelationalTablet() {
40
40
ColumnCategory::TAG,
41
41
ColumnCategory::TAG,
42
42
ColumnCategory::ATTRIBUTE,
43
- ColumnCategory::MEASUREMENT ,
44
- ColumnCategory::MEASUREMENT
43
+ ColumnCategory::FIELD ,
44
+ ColumnCategory::FIELD
45
45
};
46
46
47
47
Tablet tablet (" table1" , schemaList, columnTypes, 100 );
@@ -67,129 +67,132 @@ void insertRelationalTablet() {
67
67
}
68
68
}
69
69
70
- template <typename T>
71
- inline void Output (vector<T> &columnNames) {
72
- for (auto &name: columnNames) {
73
- cout << name << " \t " ;
70
+ void Output (unique_ptr<SessionDataSet> &dataSet) {
71
+ for (const string &name: dataSet->getColumnNames ()) {
72
+ cout << name << " " ;
73
+ }
74
+ cout << endl;
75
+ while (dataSet->hasNext ()) {
76
+ cout << dataSet->next ()->toString ();
77
+ }
78
+ cout << endl;
79
+ }
80
+
81
+ void OutputWithType (unique_ptr<SessionDataSet> &dataSet) {
82
+ for (const string &name: dataSet->getColumnNames ()) {
83
+ cout << name << " " ;
84
+ }
85
+ cout << endl;
86
+ for (const string &type: dataSet->getColumnTypeList ()) {
87
+ cout << type << " " ;
88
+ }
89
+ cout << endl;
90
+ while (dataSet->hasNext ()) {
91
+ cout << dataSet->next ()->toString ();
74
92
}
75
93
cout << endl;
76
94
}
77
95
78
96
int main () {
79
97
try {
80
- session = new TableSessionBuilder ()
81
- .host (" 127.0.0.1" )
82
- .rpcPort (6667 )
83
- .username (" root" )
84
- .password (" root" )
85
- .build ();
86
-
87
- cout << " Create Database db1,db2" << endl;
98
+ session = (new TableSessionBuilder ())
99
+ ->host (" 127.0.0.1" )
100
+ ->rpcPort (6667 )
101
+ ->username (" root" )
102
+ ->password (" root" )
103
+ ->build ();
104
+
105
+
106
+ cout << " [Create Database db1,db2]\n " << endl;
88
107
try {
89
108
session->executeNonQueryStatement (" CREATE DATABASE IF NOT EXISTS db1" );
90
109
session->executeNonQueryStatement (" CREATE DATABASE IF NOT EXISTS db2" );
91
110
} catch (IoTDBException &e) {
92
111
cout << e.what () << endl;
93
112
}
94
113
95
- cout << " Use db1 as database" << endl;
114
+ cout << " [ Use db1 as database] \n " << endl;
96
115
try {
97
116
session->executeNonQueryStatement (" USE db1" );
98
117
} catch (IoTDBException &e) {
99
118
cout << e.what () << endl;
100
119
}
101
120
102
- cout << " Create Table table1,table2" << endl;
121
+ cout << " [ Create Table table1,table2] \n " << endl;
103
122
try {
104
- session->executeNonQueryStatement (" db1.table1(region_id STRING TAG, plant_id STRING TAG, device_id STRING TAG, model STRING ATTRIBUTE, temperature FLOAT FIELD, humidity DOUBLE FIELD) with (TTL=3600000)" );
123
+ session->executeNonQueryStatement (" create table db1.table1(region_id STRING TAG, plant_id STRING TAG, device_id STRING TAG, model STRING ATTRIBUTE, temperature FLOAT FIELD, humidity DOUBLE FIELD) with (TTL=3600000)" );
105
124
session->executeNonQueryStatement (" create table db2.table2(region_id STRING TAG, plant_id STRING TAG, color STRING ATTRIBUTE, temperature FLOAT FIELD, speed DOUBLE FIELD) with (TTL=6600000)" );
106
125
} catch (IoTDBException &e) {
107
126
cout << e.what () << endl;
108
127
}
109
128
110
- cout << " Show Tables" << endl;
129
+ cout << " [ Show Tables] \n " << endl;
111
130
try {
112
- SessionDataSet dataSet = session->executeQueryStatement (" SHOW TABLES" );
113
- Output (dataSet.getColumnNames ());
114
- while (dataSet.hasNext ()) {
115
- Output (dataSet.next ());
116
- }
131
+ unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement (" SHOW TABLES" );
132
+ Output (dataSet);
117
133
} catch (IoTDBException &e) {
118
134
cout << e.what () << endl;
119
135
}
120
136
121
- cout << " Show tables from specific database" << endl;
137
+ cout << " [ Show tables from specific database] \n " << endl;
122
138
try {
123
- SessionDataSet dataSet = session->executeQueryStatement (" SHOW TABLES FROM db1" );
124
- Output (dataSet.getColumnNames ());
125
- while (dataSet.hasNext ()) {
126
- Output (dataSet.next ());
127
- }
139
+ unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement (" SHOW TABLES FROM db1" );
140
+ Output (dataSet);
128
141
} catch (IoTDBException &e) {
129
142
cout << e.what () << endl;
130
143
}
131
144
132
- cout << " InsertTablet" << endl;
145
+ cout << " [ InsertTablet] \n " << endl;
133
146
try {
134
147
insertRelationalTablet ();
135
148
} catch (IoTDBException &e) {
136
149
cout << e.what () << endl;
137
150
}
138
151
139
- cout << " Query Table Data" << endl;
152
+ cout << " [ Query Table Data] \n " << endl;
140
153
try {
141
- SessionDataSet dataSet = session->executeQueryStatement (" SELECT * FROM table1"
154
+ unique_ptr< SessionDataSet> dataSet = session->executeQueryStatement (" SELECT * FROM table1"
142
155
" where region_id = '1' and plant_id in ('3', '5') and device_id = '3'" );
143
- Output (dataSet.getColumnNames ());
144
- Output (dataSet.getColumnTypeList ());
145
- while (dataSet.hasNext ()) {
146
- Output (dataSet.next ());
147
- }
156
+ OutputWithType (dataSet);
148
157
} catch (IoTDBException &e) {
149
158
cout << e.what () << endl;
150
159
}
151
160
152
161
session->close ();
153
162
154
163
// specify database in constructor
155
- session = new TableSessionBuilder ()
156
- . host (" 127.0.0.1" )
157
- . rpcPort (6667 )
158
- . username (" root" )
159
- . password (" root" )
160
- . database (" db1" )
161
- . build ();
162
-
163
- cout << " Show tables from current database(db1)" << endl;
164
+ session = ( new TableSessionBuilder () )
165
+ -> host (" 127.0.0.1" )
166
+ -> rpcPort (6667 )
167
+ -> username (" root" )
168
+ -> password (" root" )
169
+ -> database (" db1" )
170
+ -> build ();
171
+
172
+ cout << " [ Show tables from current database(db1)] \n " << endl;
164
173
try {
165
- SessionDataSet dataSet = session->executeQueryStatement (" SHOW TABLES" );
166
- Output (dataSet.getColumnNames ());
167
- while (dataSet.hasNext ()) {
168
- Output (dataSet.next ());
169
- }
174
+ unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement (" SHOW TABLES" );
175
+ Output (dataSet);
170
176
} catch (IoTDBException &e) {
171
177
cout << e.what () << endl;
172
178
}
173
179
174
- cout << " Change database to db2" << endl;
180
+ cout << " [ Change database to db2] \n " << endl;
175
181
try {
176
182
session->executeNonQueryStatement (" USE db2" );
177
183
} catch (IoTDBException &e) {
178
184
cout << e.what () << endl;
179
185
}
180
186
181
- cout << " Show tables from current database(db2)" << endl;
187
+ cout << " [ Show tables from current database(db2)] \n " << endl;
182
188
try {
183
- SessionDataSet dataSet = session->executeQueryStatement (" SHOW TABLES" );
184
- Output (dataSet.getColumnNames ());
185
- while (dataSet.hasNext ()) {
186
- Output (dataSet.next ());
187
- }
189
+ unique_ptr<SessionDataSet> dataSet = session->executeQueryStatement (" SHOW TABLES" );
190
+ Output (dataSet);
188
191
} catch (IoTDBException &e) {
189
192
cout << e.what () << endl;
190
193
}
191
194
192
- cout << " Drop Database db1,db2" << endl;
195
+ cout << " [ Drop Database db1,db2] \n " << endl;
193
196
try {
194
197
session->executeNonQueryStatement (" DROP DATABASE db1" );
195
198
session->executeNonQueryStatement (" DROP DATABASE db2" );
0 commit comments