Merge lp:~mmcm/akiban-server/pg-chartio-queries into lp:~akiban-technologies/akiban-server/trunk

Proposed by Mike McMahon
Status: Merged
Approved by: Mike McMahon
Approved revision: 2634
Merged at revision: 2632
Proposed branch: lp:~mmcm/akiban-server/pg-chartio-queries
Merge into: lp:~akiban-technologies/akiban-server/trunk
Diff against target: 224 lines (+176/-1)
2 files modified
src/main/java/com/akiban/sql/pg/PostgresEmulatedMetaDataStatement.java (+167/-1)
src/main/java/com/akiban/sql/pg/PostgresServerConnection.java (+9/-0)
To merge this branch: bzr merge lp:~mmcm/akiban-server/pg-chartio-queries
Reviewer Review Type Date Requested Status
Akiban Build User Needs Fixing
Nathan Williams Approve
Review via email: mp+159902@code.launchpad.net

Description of the change

Add emulation for the simple queries that chartio sends when setting up a data source.

I am not too confident that this will be enough, but putting it into the cloud should allow testing to see whether it is enough for a demo at least.

Because they also use prepared statements, need to run the unparsed matchers then, too. I don't think this will any significant effects.

To post a comment you must log in.
Revision history for this message
Nathan Williams (nwilliams) wrote :

Delightful.

review: Approve
Revision history for this message
Akiban Build User (build-akiban) wrote :

There were 2 failures during build/test:

* job server-build failed at build number 3978: http://172.16.20.104:8080/job/server-build/3978/

* view must-pass failed: server-build is yellow

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/main/java/com/akiban/sql/pg/PostgresEmulatedMetaDataStatement.java'
--- src/main/java/com/akiban/sql/pg/PostgresEmulatedMetaDataStatement.java 2013-04-04 21:44:13 +0000
+++ src/main/java/com/akiban/sql/pg/PostgresEmulatedMetaDataStatement.java 2013-04-19 22:19:23 +0000
@@ -128,7 +128,10 @@
128 "FROM pg_catalog.pg_trigger t\\s+" +128 "FROM pg_catalog.pg_trigger t\\s+" +
129 "WHERE t.tgrelid = '(-?\\d+)' AND (?:t.tgconstraint = 0|" + // 2129 "WHERE t.tgrelid = '(-?\\d+)' AND (?:t.tgconstraint = 0|" + // 2
130 "\\(not tgisconstraint OR NOT EXISTS \\(SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c ON \\(d.refclassid = c.tableoid AND d.refobjid = c.oid\\) WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'\\)\\))(?:\\s+ORDER BY 1)?;?", true),130 "\\(not tgisconstraint OR NOT EXISTS \\(SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c ON \\(d.refclassid = c.tableoid AND d.refobjid = c.oid\\) WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'\\)\\))(?:\\s+ORDER BY 1)?;?", true),
131 PSQL_DESCRIBE_VIEW("SELECT pg_catalog.pg_get_viewdef\\('(-?\\d+)'::pg_catalog.oid, true\\);?", true);131 PSQL_DESCRIBE_VIEW("SELECT pg_catalog.pg_get_viewdef\\('(-?\\d+)'::pg_catalog.oid, true\\);?", true),
132 CHARTIO_TABLES("SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME, CASE n.nspname ~ '^pg_' OR n.nspname = 'information_schema' WHEN true THEN CASE WHEN n.nspname = 'pg_catalog' OR n.nspname = 'information_schema' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TABLE' WHEN 'v' THEN 'SYSTEM VIEW' WHEN 'i' THEN 'SYSTEM INDEX' ELSE NULL END WHEN n.nspname = 'pg_toast' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TOAST TABLE' WHEN 'i' THEN 'SYSTEM TOAST INDEX' ELSE NULL END ELSE CASE c.relkind WHEN 'r' THEN 'TEMPORARY TABLE' WHEN 'i' THEN 'TEMPORARY INDEX' WHEN 'S' THEN 'TEMPORARY SEQUENCE' WHEN 'v' THEN 'TEMPORARY VIEW' ELSE NULL END END WHEN false THEN CASE c.relkind WHEN 'r' THEN 'TABLE' WHEN 'i' THEN 'INDEX' WHEN 'S' THEN 'SEQUENCE' WHEN 'v' THEN 'VIEW' WHEN 'c' THEN 'TYPE' WHEN 'f' THEN 'FOREIGN TABLE' ELSE NULL END ELSE NULL END AS TABLE_TYPE, d.description AS REMARKS FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dn.oid=dc.relnamespace AND dn.nspname='pg_catalog') WHERE c.relnamespace = n.oid AND (false OR ( c.relkind = 'r' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' ) OR ( c.relkind = 'v' AND n.nspname <> 'pg_catalog' AND n.nspname <> 'information_schema' ) ) ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME "),
133 CHARTIO_KEYS("SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, ct.relname AS TABLE_NAME, a.attname AS COLUMN_NAME, \\(i.keys\\).n AS KEY_SEQ, ci.relname AS PK_NAME FROM pg_catalog.pg_class ct JOIN pg_catalog.pg_attribute a ON \\(ct.oid = a.attrelid\\) JOIN pg_catalog.pg_namespace n ON \\(ct.relnamespace = n.oid\\) JOIN \\(SELECT i.indexrelid, i.indrelid, i.indisprimary, information_schema._pg_expandarray\\(i.indkey\\) AS keys FROM pg_catalog.pg_index i\\) i ON \\(a.attnum = \\(i.keys\\).x AND a.attrelid = i.indrelid\\) JOIN pg_catalog.pg_class ci ON \\(ci.oid = i.indexrelid\\) WHERE true AND ct.relname = E'(.+)' AND i.indisprimary ORDER BY table_name, pk_name, key_seq", true),
134 CHARTIO_COLUMNS("SELECT \\* FROM \\(SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull OR \\(t.typtype = 'd' AND t.typnotnull\\) AS attnotnull,a.atttypmod,a.attlen,row_number\\(\\) OVER \\(PARTITION BY a.attrelid ORDER BY a.attnum\\) AS attnum, pg_catalog.pg_get_expr\\(def.adbin, def.adrelid\\) AS adsrc,dsc.description,t.typbasetype,t.typtype FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_class c ON \\(c.relnamespace = n.oid\\) JOIN pg_catalog.pg_attribute a ON \\(a.attrelid=c.oid\\) JOIN pg_catalog.pg_type t ON \\(a.atttypid = t.oid\\) LEFT JOIN pg_catalog.pg_attrdef def ON \\(a.attrelid=def.adrelid AND a.attnum = def.adnum\\) LEFT JOIN pg_catalog.pg_description dsc ON \\(c.oid=dsc.objoid AND a.attnum = dsc.objsubid\\) LEFT JOIN pg_catalog.pg_class dc ON \\(dc.oid=dsc.classoid AND dc.relname='pg_class'\\) LEFT JOIN pg_catalog.pg_namespace dn ON \\(dc.relnamespace=dn.oid AND dn.nspname='pg_catalog'\\) WHERE a.attnum > 0 AND NOT a.attisdropped AND c.relname LIKE E'(.+)'\\) c WHERE true ORDER BY nspname,c.relname,attnum ", true);
132135
133 private String sql;136 private String sql;
134 private Pattern pattern;137 private Pattern pattern;
@@ -185,6 +188,8 @@
185 new PostgresType(PostgresType.TypeOid.BOOL_TYPE_OID, (short)1, -1, AkType.BOOL, AkBool.INSTANCE.instance(FIELDS_NULLABLE));188 new PostgresType(PostgresType.TypeOid.BOOL_TYPE_OID, (short)1, -1, AkType.BOOL, AkBool.INSTANCE.instance(FIELDS_NULLABLE));
186 static final PostgresType INT2_PG_TYPE = 189 static final PostgresType INT2_PG_TYPE =
187 new PostgresType(PostgresType.TypeOid.INT2_TYPE_OID, (short)2, -1, AkType.LONG, MNumeric.SMALLINT.instance(FIELDS_NULLABLE));190 new PostgresType(PostgresType.TypeOid.INT2_TYPE_OID, (short)2, -1, AkType.LONG, MNumeric.SMALLINT.instance(FIELDS_NULLABLE));
191 static final PostgresType INT4_PG_TYPE =
192 new PostgresType(PostgresType.TypeOid.INT4_TYPE_OID, (short)4, -1, AkType.LONG, MNumeric.INT.instance(FIELDS_NULLABLE));
188 static final PostgresType OID_PG_TYPE = 193 static final PostgresType OID_PG_TYPE =
189 new PostgresType(PostgresType.TypeOid.OID_TYPE_OID, (short)4, -1, AkType.LONG, MNumeric.INT.instance(FIELDS_NULLABLE));194 new PostgresType(PostgresType.TypeOid.OID_TYPE_OID, (short)4, -1, AkType.LONG, MNumeric.INT.instance(FIELDS_NULLABLE));
190 static final PostgresType TYPNAME_PG_TYPE = 195 static final PostgresType TYPNAME_PG_TYPE =
@@ -325,6 +330,21 @@
325 names = new String[] { "pg_get_viewdef" };330 names = new String[] { "pg_get_viewdef" };
326 types = new PostgresType[] { VIEWDEF_PG_TYPE };331 types = new PostgresType[] { VIEWDEF_PG_TYPE };
327 break;332 break;
333 case CHARTIO_TABLES:
334 ncols = 5;
335 names = new String[] { "table_cat", "table_schem", "table_name", "table_type", "remarks" };
336 types = new PostgresType[] { IDENT_PG_TYPE, IDENT_PG_TYPE, IDENT_PG_TYPE, LIST_TYPE_PG_TYPE, CHAR0_PG_TYPE };
337 break;
338 case CHARTIO_KEYS:
339 ncols = 6;
340 names = new String[] { "table_cat", "table_schem", "table_name", "column_name", "key_seq", "pk_name" };
341 types = new PostgresType[] { IDENT_PG_TYPE, IDENT_PG_TYPE, IDENT_PG_TYPE, IDENT_PG_TYPE, INT2_PG_TYPE, IDENT_PG_TYPE };
342 break;
343 case CHARTIO_COLUMNS:
344 ncols = 12;
345 names = new String[] { "nspname", "relname", "attname", "atttypid", "attnotnull", "atttypmod", "attlen", "attnum", "adsrc", "description", "typbasetype", "typtype" };
346 types = new PostgresType[] { IDENT_PG_TYPE, IDENT_PG_TYPE, IDENT_PG_TYPE, OID_PG_TYPE, CHAR1_PG_TYPE, INT4_PG_TYPE, INT2_PG_TYPE, INT2_PG_TYPE, CHAR0_PG_TYPE, CHAR0_PG_TYPE, OID_PG_TYPE, CHAR1_PG_TYPE };
347 break;
328 default:348 default:
329 return;349 return;
330 }350 }
@@ -415,6 +435,15 @@
415 case PSQL_DESCRIBE_VIEW:435 case PSQL_DESCRIBE_VIEW:
416 nrows = psqlDescribeViewQuery(server, messenger, encoder, maxrows, usePVals);436 nrows = psqlDescribeViewQuery(server, messenger, encoder, maxrows, usePVals);
417 break;437 break;
438 case CHARTIO_TABLES:
439 nrows = chartioTablesQuery(server, messenger, encoder, maxrows, usePVals);
440 break;
441 case CHARTIO_KEYS:
442 nrows = chartioKeysQuery(server, messenger, encoder, maxrows, usePVals);
443 break;
444 case CHARTIO_COLUMNS:
445 nrows = chartioColumnsQuery(server, messenger, encoder, maxrows, usePVals);
446 break;
418 }447 }
419 { 448 {
420 messenger.beginMessage(PostgresMessages.COMMAND_COMPLETE_TYPE.code());449 messenger.beginMessage(PostgresMessages.COMMAND_COMPLETE_TYPE.code());
@@ -1106,4 +1135,141 @@
1106 return 1;1135 return 1;
1107 }1136 }
11081137
1138 private int chartioTablesQuery(PostgresServerSession server, PostgresMessenger messenger, ServerValueEncoder encoder, int maxrows, boolean usePVals) throws IOException {
1139 int nrows = 0;
1140 List<Columnar> tables = new ArrayList<>();
1141 AkibanInformationSchema ais = server.getAIS();
1142 tables.addAll(ais.getUserTables().values());
1143 tables.addAll(ais.getViews().values());
1144 Iterator<Columnar> iter = tables.iterator();
1145 while (iter.hasNext()) {
1146 TableName name = iter.next().getName();
1147 if (name.getSchemaName().equals(TableName.INFORMATION_SCHEMA) ||
1148 name.getSchemaName().equals(TableName.SECURITY_SCHEMA) ||
1149 !server.isSchemaAccessible(name.getSchemaName()))
1150 iter.remove();
1151 }
1152 Collections.sort(tables, tablesByName);
1153 for (Columnar table : tables) {
1154 TableName name = table.getName();
1155 messenger.beginMessage(PostgresMessages.DATA_ROW_TYPE.code());
1156 messenger.writeShort(5); // 5 columns for this query
1157 writeColumn(messenger, encoder, usePVals,
1158 null, IDENT_PG_TYPE);
1159 writeColumn(messenger, encoder, usePVals,
1160 name.getSchemaName(), IDENT_PG_TYPE);
1161 writeColumn(messenger, encoder, usePVals,
1162 name.getTableName(), IDENT_PG_TYPE);
1163 String type = table.isView() ? "VIEW" : "TABLE";
1164 writeColumn(messenger, encoder, usePVals,
1165 type, LIST_TYPE_PG_TYPE);
1166 writeColumn(messenger, encoder, usePVals,
1167 null, CHAR0_PG_TYPE);
1168 messenger.sendMessage();
1169 nrows++;
1170 if ((maxrows > 0) && (nrows >= maxrows)) {
1171 break;
1172 }
1173 }
1174 return nrows;
1175 }
1176
1177 private int chartioKeysQuery(PostgresServerSession server, PostgresMessenger messenger, ServerValueEncoder encoder, int maxrows, boolean usePVals) throws IOException {
1178 int nrows = 0;
1179 String name = groups.get(1);
1180 AkibanInformationSchema ais = server.getAIS();
1181 List<UserTable> tables = new ArrayList<>();
1182 for (UserTable table : ais.getUserTables().values()) {
1183 TableName tableName = table.getName();
1184 if (server.isSchemaAccessible(tableName.getSchemaName()) &&
1185 tableName.getTableName().equalsIgnoreCase(name)) {
1186 tables.add(table);
1187 }
1188 }
1189 Collections.sort(tables, tablesByName);
1190 rows:
1191 for (UserTable table : tables) {
1192 TableName tableName = table.getName();
1193 TableIndex index = table.getIndex(Index.PRIMARY_KEY_CONSTRAINT);
1194 if (index != null) {
1195 for (IndexColumn column : index.getKeyColumns()) {
1196 messenger.beginMessage(PostgresMessages.DATA_ROW_TYPE.code());
1197 messenger.writeShort(6); // 6 columns for this query
1198 writeColumn(messenger, encoder, usePVals,
1199 null, IDENT_PG_TYPE);
1200 writeColumn(messenger, encoder, usePVals,
1201 tableName.getSchemaName(), IDENT_PG_TYPE);
1202 writeColumn(messenger, encoder, usePVals,
1203 tableName.getTableName(), IDENT_PG_TYPE);
1204 writeColumn(messenger, encoder, usePVals,
1205 column.getColumn().getName(), IDENT_PG_TYPE);
1206 writeColumn(messenger, encoder, usePVals,
1207 (short)(column.getPosition() + 1), INT2_PG_TYPE);
1208 writeColumn(messenger, encoder, usePVals,
1209 index.getIndexName().getName(), IDENT_PG_TYPE);
1210 messenger.sendMessage();
1211 nrows++;
1212 if ((maxrows > 0) && (nrows >= maxrows)) {
1213 break rows;
1214 }
1215 }
1216 }
1217 }
1218 return nrows;
1219 }
1220
1221 private int chartioColumnsQuery(PostgresServerSession server, PostgresMessenger messenger, ServerValueEncoder encoder, int maxrows, boolean usePVals) throws IOException {
1222 int nrows = 0;
1223 String name = groups.get(1);
1224 AkibanInformationSchema ais = server.getAIS();
1225 List<UserTable> tables = new ArrayList<>();
1226 for (UserTable table : ais.getUserTables().values()) {
1227 TableName tableName = table.getName();
1228 if (server.isSchemaAccessible(tableName.getSchemaName()) &&
1229 tableName.getTableName().equalsIgnoreCase(name)) {
1230 tables.add(table);
1231 }
1232 }
1233 Collections.sort(tables, tablesByName);
1234 rows:
1235 for (UserTable table : tables) {
1236 TableName tableName = table.getName();
1237 for (Column column : table.getColumns()) {
1238 PostgresType type = PostgresType.fromAIS(column);
1239 messenger.beginMessage(PostgresMessages.DATA_ROW_TYPE.code());
1240 messenger.writeShort(12); // 12 columns for this query
1241 writeColumn(messenger, encoder, usePVals,
1242 tableName.getSchemaName(), IDENT_PG_TYPE);
1243 writeColumn(messenger, encoder, usePVals,
1244 tableName.getTableName(), IDENT_PG_TYPE);
1245 writeColumn(messenger, encoder, usePVals,
1246 column.getName(), IDENT_PG_TYPE);
1247 writeColumn(messenger, encoder, usePVals,
1248 type.getOid(), OID_PG_TYPE);
1249 writeColumn(messenger, encoder, usePVals,
1250 column.getNullable() ? "t" : "f", CHAR1_PG_TYPE);
1251 writeColumn(messenger, encoder, usePVals,
1252 type.getModifier(), INT4_PG_TYPE);
1253 writeColumn(messenger, encoder, usePVals,
1254 type.getLength(), INT2_PG_TYPE);
1255 writeColumn(messenger, encoder, usePVals,
1256 (short)(column.getPosition() + 1), INT2_PG_TYPE);
1257 writeColumn(messenger, encoder, usePVals,
1258 null, CHAR0_PG_TYPE);
1259 writeColumn(messenger, encoder, usePVals,
1260 null, CHAR0_PG_TYPE);
1261 writeColumn(messenger, encoder, usePVals,
1262 0, OID_PG_TYPE);
1263 writeColumn(messenger, encoder, usePVals,
1264 "b", CHAR1_PG_TYPE);
1265 messenger.sendMessage();
1266 nrows++;
1267 if ((maxrows > 0) && (nrows >= maxrows)) {
1268 break rows;
1269 }
1270 }
1271 }
1272 return nrows;
1273 }
1274
1109}1275}
11101276
=== modified file 'src/main/java/com/akiban/sql/pg/PostgresServerConnection.java'
--- src/main/java/com/akiban/sql/pg/PostgresServerConnection.java 2013-04-04 21:44:13 +0000
+++ src/main/java/com/akiban/sql/pg/PostgresServerConnection.java 2013-04-19 22:19:23 +0000
@@ -751,6 +751,15 @@
751 if (statementCache != null)751 if (statementCache != null)
752 pstmt = statementCache.get(sql);752 pstmt = statementCache.get(sql);
753 if (pstmt == null) {753 if (pstmt == null) {
754 for (PostgresStatementParser parser : unparsedGenerators) {
755 pstmt = parser.parse(this, sql, null);
756 if (pstmt != null) {
757 pstmt.setAISGeneration(ais.getGeneration());
758 break;
759 }
760 }
761 }
762 if (pstmt == null) {
754 StatementNode stmt;763 StatementNode stmt;
755 List<ParameterNode> params;764 List<ParameterNode> params;
756 try {765 try {

Subscribers

People subscribed via source and target branches