@Test public void testInsertAsSelect() throws Exception { String expectedData = "a\tb\tc\td\te\tf\tg\th\ti\tj\tk\tl\tm\tn\to\tp\n" + "1569490116\tNaN\tfalse\t\tNaN\t0.7611\t428\t-1593\t2015-04-04T16:34:47.226Z\t\t\t185\t7039584373105579285\t1970-01-01T00:00:00.000000Z\t4\t00000000 af 19 c4 95 94 36 53 49 b4 59 7e\n" + "1253890363\t10\tfalse\tXYS\t0.1911234617573182\t0.5793\t881\t-1379\t\t2015-03-04T23:08:35.722465Z\tHYRX\t188\t-4986232506486815364\t1970-01-01T00:16:40.000000Z\t50\t00000000 42 fc 31 79 5f 8b 81 2b 93 4d 1a 8e 78 b5\n" + "-1819240775\t27\ttrue\tGOO\t0.04142812470232493\t0.9205\t97\t-9039\t2015-08-25T03:15:07.653Z\t2015-12-06T09:41:30.297134Z\tHYRX\t109\t571924429013198086\t1970-01-01T00:33:20.000000Z\t21\t\n" + "-1201923128\t18\ttrue\tUVS\t0.7588175403454873\t0.5779\t480\t-4379\t2015-12-16T09:15:02.086Z\t2015-05-31T18:12:45.686366Z\tCPSW\tNaN\t-6161552193869048721\t1970-01-01T00:50:00.000000Z\t27\t00000000 28 c7 84 47 dc d2 85 7f a5 b8 7b 4a 9d 46\n" + "865832060\tNaN\ttrue\t\t0.14830552335848957\t0.9442\t95\t2508\t\t2015-10-20T09:33:20.502524Z\t\tNaN\t-3289070757475856942\t1970-01-01T01:06:40.000000Z\t40\t00000000 f2 3c ed 39 ac a8 3b a6 dc 3b 7d 2b e3 92 fe 69\n" + "00000010 38 e1\n" + "1100812407\t22\tfalse\tOVL\tNaN\t0.7633\t698\t-17778\t2015-09-13T09:55:17.815Z\t\tCPSW\t182\t-8757007522346766135\t1970-01-01T01:23:20.000000Z\t23\t\n" + "1677463366\t18\tfalse\tMNZ\t0.33747075654972813\t0.1179\t533\t18904\t2015-05-13T23:13:05.262Z\t2015-05-10T00:20:17.926993Z\t\t175\t6351664568801157821\t1970-01-01T01:40:00.000000Z\t29\t00000000 5d d0 eb 67 44 a7 6a 71 34 e0 b0 e9 98 f7 67 62\n" + "00000010 28 60\n" + "39497392\t4\tfalse\tUOH\t0.029227696942726644\t0.1718\t652\t14242\t\t2015-05-24T22:09:55.175991Z\tVTJW\t141\t3527911398466283309\t1970-01-01T01:56:40.000000Z\t9\t00000000 d9 6f 04 ab 27 47 8f 23 3f ae 7c 9f 77 04 e9 0c\n" + "00000010 ea 4e ea 8b\n" + "1545963509\t10\tfalse\tNWI\t0.11371841836123953\t0.0620\t356\t-29980\t2015-09-12T14:33:11.105Z\t2015-08-06T04:51:01.526782Z\t\t168\t6380499796471875623\t1970-01-01T02:13:20.000000Z\t13\t00000000 54 52 d0 29 26 c5 aa da 18 ce 5f b2 8b 5c 54 90\n" + "53462821\t4\tfalse\tGOO\t0.05514933756198426\t0.1195\t115\t-6087\t2015-08-09T19:28:14.249Z\t2015-09-20T01:50:37.694867Z\tCPSW\t145\t-7212878484370155026\t1970-01-01T02:30:00.000000Z\t46\t\n" + "-2139296159\t30\tfalse\t\t0.18586435581637295\t0.5638\t299\t21020\t2015-12-30T22:10:50.759Z\t2015-01-19T15:54:44.696040Z\tHYRX\t105\t-3463832009795858033\t1970-01-01T02:46:40.000000Z\t38\t00000000 b8 07 b1 32 57 ff 9a ef 88 cb 4b\n" + "-406528351\t21\tfalse\tNLE\tNaN\tNaN\t968\t21057\t2015-10-17T07:20:26.881Z\t2015-06-02T13:00:45.180827Z\tPEHN\t102\t5360746485515325739\t1970-01-01T03:03:20.000000Z\t43\t\n" + "415709351\t17\tfalse\tGQZ\t0.49199001716312474\t0.6292\t581\t18605\t2015-03-04T06:48:42.194Z\t2015-08-14T15:51:23.307152Z\tHYRX\t185\t-5611837907908424613\t1970-01-01T03:20:00.000000Z\t19\t00000000 20 e2 37 f2 64 43 84 55 a0 dd 44 11 e2 a3 24 4e\n" + "00000010 44 a8 0d fe\n" + "-1387693529\t19\ttrue\tMCG\t0.848083900630095\t0.4699\t119\t24206\t2015-03-01T23:54:10.204Z\t2015-10-01T12:02:08.698373Z\t\t175\t3669882909701240516\t1970-01-01T03:36:40.000000Z\t12\t00000000 8f bb 2a 4b af 8f 89 df 35 8f da fe 33 98 80 85\n" + "00000010 20 53 3b 51\n" + "346891421\t21\tfalse\t\t0.933609514582851\t0.6380\t405\t15084\t2015-10-12T05:36:54.066Z\t2015-11-16T05:48:57.958190Z\tPEHN\t196\t-9200716729349404576\t1970-01-01T03:53:20.000000Z\t43\t\n" + "263487884\t27\ttrue\tHZQ\t0.7039785408034679\t0.8461\t834\t31562\t2015-08-04T00:55:25.323Z\t2015-07-25T18:26:42.499255Z\tHYRX\t128\t8196544381931602027\t1970-01-01T04:10:00.000000Z\t15\t00000000 71 76 bc 45 24 cd 13 00 7c fb 01 19 ca f2\n" + "-1034870849\t9\tfalse\tLSV\t0.6506604601705693\t0.7020\t110\t-838\t2015-08-17T23:50:39.534Z\t2015-03-17T03:23:26.126568Z\tHYRX\tNaN\t-6929866925584807039\t1970-01-01T04:26:40.000000Z\t4\t00000000 4b fb 2d 16 f3 89 a3 83 64 de\n" + "1848218326\t26\ttrue\tSUW\t0.8034049105590781\t0.0440\t854\t-3502\t2015-04-04T20:55:02.116Z\t2015-11-23T07:46:10.570856Z\t\t145\t4290477379978201771\t1970-01-01T04:43:20.000000Z\t35\t00000000 6d 54 75 10 b3 4c 0e 8f f1 0c c5 60 b7 d1 5a\n" + "-1496904948\t5\ttrue\tDBZ\t0.2862717364877081\tNaN\t764\t5698\t2015-02-06T02:49:54.147Z\t\t\tNaN\t-3058745577013275321\t1970-01-01T05:00:00.000000Z\t19\t00000000 d4 ab be 30 fa 8d ac 3d 98 a0 ad 9a 5d\n" + "856634079\t20\ttrue\tRJU\t0.10820602386069589\t0.4565\t669\t13505\t2015-11-14T15:19:19.390Z\t\tVTJW\t134\t-3700177025310488849\t1970-01-01T05:16:40.000000Z\t3\t00000000 f8 a1 46 87 28 92 a3 9b e3 cb c2 64 8a b0 35 d8\n" + "00000010 ab 3f a1 f5\n"; testInsertAsSelect(expectedData, "create table x (a INT, b INT, c BOOLEAN, d STRING, e DOUBLE, f FLOAT, g SHORT, h SHORT, i DATE, j TIMESTAMP, k SYMBOL, l LONG, m LONG, n TIMESTAMP, o BYTE, p BINARY)", "insert into x " + "select" + " rnd_int()," + " rnd_int(0, 30, 2)," + " rnd_boolean()," + " rnd_str(3,3,2)," + " rnd_double(2)," + " rnd_float(2)," + " rnd_short(10,1024)," + " rnd_short()," + " rnd_date(to_date('2015', 'yyyy'), to_date('2016', 'yyyy'), 2)," + " rnd_timestamp(to_timestamp('2015', 'yyyy'), to_timestamp('2016', 'yyyy'), 2)," + " rnd_symbol(4,4,4,2)," + " rnd_long(100,200,2)," + " rnd_long()," + " timestamp_sequence(0, 1000000000)," + " rnd_byte(2,50)," + " rnd_bin(10, 20, 2)" + " from long_sequence(20)", "select * from x" ); }
private CompiledQuery insertAsSelect(ExecutionModel executionModel, SqlExecutionContext executionContext) throws SqlException { final InsertModel model = (InsertModel) executionModel; final ExpressionNode name = model.getTableName(); tableExistsOrFail(name.position, name.token, executionContext); try (TableWriter writer = engine.getWriter(executionContext.getCairoSecurityContext(), name.token); RecordCursorFactory factory = generate(model.getQueryModel(), executionContext)) { final RecordMetadata cursorMetadata = factory.getMetadata(); final RecordMetadata writerMetadata = writer.getMetadata(); final int writerTimestampIndex = writerMetadata.getTimestampIndex(); final int cursorTimestampIndex = cursorMetadata.getTimestampIndex(); final int cursorColumnCount = cursorMetadata.getColumnCount(); if (writerTimestampIndex > -1 && cursorTimestampIndex == -1) { if (cursorColumnCount <= writerTimestampIndex) { throw SqlException.$(name.position, "select clause must provide timestamp column"); } else if (cursorMetadata.getColumnType(writerTimestampIndex) != ColumnType.TIMESTAMP) { throw SqlException.$(name.position, "expected timestamp column but type is ").put(ColumnType.nameOf(cursorMetadata.getColumnType(writerTimestampIndex))); } } if (writerTimestampIndex > -1 && cursorTimestampIndex > -1 && writerTimestampIndex != cursorTimestampIndex) { throw SqlException.$(name.position, "nominated column of existing table (").put(writerTimestampIndex).put(") does not match nominated column in select query (").put(cursorTimestampIndex).put(')'); } final RecordToRowCopier copier; CharSequenceHashSet columnSet = model.getColumnSet(); final int columnSetSize = columnSet.size(); if (columnSetSize > 0) { listColumnFilter.clear(); for (int i = 0; i < columnSetSize; i++) { CharSequence columnName = columnSet.get(i); int index = writerMetadata.getColumnIndexQuiet(columnName); if (index == -1) { throw SqlException.invalidColumn(model.getColumnPosition(i), columnName); } int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(index); if (isAssignableFrom(toType, fromType)) { listColumnFilter.add(index); } else { throw SqlException.inconvertibleTypes( model.getColumnPosition(i), fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } } copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, listColumnFilter); } else { final int n = writerMetadata.getColumnCount(); if (n > cursorMetadata.getColumnCount()) { throw SqlException.$(model.getSelectKeywordPosition(), "not enough columns selected"); } for (int i = 0; i < n; i++) { int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(i); if (isAssignableFrom(toType, fromType)) { continue; } assert i < model.getQueryModel().getBottomUpColumns().size(); throw SqlException.inconvertibleTypes( model.getQueryModel().getBottomUpColumns().getQuick(i).getAst().position, fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } entityColumnFilter.of(writerMetadata.getColumnCount()); copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, entityColumnFilter); } try (RecordCursor cursor = factory.getCursor(executionContext)) { try { if (writerTimestampIndex == -1) { copyUnordered(cursor, writer, copier); } else { copyOrdered(writer, cursor, copier, writerTimestampIndex); } } catch (CairoException e) { writer.rollback(); throw e; } } } return compiledQuery.ofInsertAsSelect(); }
SqlCompiler implements Closeable { private CompiledQuery insertAsSelect(ExecutionModel executionModel, SqlExecutionContext executionContext) throws SqlException { final InsertModel model = (InsertModel) executionModel; final ExpressionNode name = model.getTableName(); tableExistsOrFail(name.position, name.token, executionContext); try (TableWriter writer = engine.getWriter(executionContext.getCairoSecurityContext(), name.token); RecordCursorFactory factory = generate(model.getQueryModel(), executionContext)) { final RecordMetadata cursorMetadata = factory.getMetadata(); final RecordMetadata writerMetadata = writer.getMetadata(); final int writerTimestampIndex = writerMetadata.getTimestampIndex(); final int cursorTimestampIndex = cursorMetadata.getTimestampIndex(); final int cursorColumnCount = cursorMetadata.getColumnCount(); if (writerTimestampIndex > -1 && cursorTimestampIndex == -1) { if (cursorColumnCount <= writerTimestampIndex) { throw SqlException.$(name.position, "select clause must provide timestamp column"); } else if (cursorMetadata.getColumnType(writerTimestampIndex) != ColumnType.TIMESTAMP) { throw SqlException.$(name.position, "expected timestamp column but type is ").put(ColumnType.nameOf(cursorMetadata.getColumnType(writerTimestampIndex))); } } if (writerTimestampIndex > -1 && cursorTimestampIndex > -1 && writerTimestampIndex != cursorTimestampIndex) { throw SqlException.$(name.position, "nominated column of existing table (").put(writerTimestampIndex).put(") does not match nominated column in select query (").put(cursorTimestampIndex).put(')'); } final RecordToRowCopier copier; CharSequenceHashSet columnSet = model.getColumnSet(); final int columnSetSize = columnSet.size(); if (columnSetSize > 0) { listColumnFilter.clear(); for (int i = 0; i < columnSetSize; i++) { CharSequence columnName = columnSet.get(i); int index = writerMetadata.getColumnIndexQuiet(columnName); if (index == -1) { throw SqlException.invalidColumn(model.getColumnPosition(i), columnName); } int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(index); if (isAssignableFrom(toType, fromType)) { listColumnFilter.add(index); } else { throw SqlException.inconvertibleTypes( model.getColumnPosition(i), fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } } copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, listColumnFilter); } else { final int n = writerMetadata.getColumnCount(); if (n > cursorMetadata.getColumnCount()) { throw SqlException.$(model.getSelectKeywordPosition(), "not enough columns selected"); } for (int i = 0; i < n; i++) { int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(i); if (isAssignableFrom(toType, fromType)) { continue; } assert i < model.getQueryModel().getBottomUpColumns().size(); throw SqlException.inconvertibleTypes( model.getQueryModel().getBottomUpColumns().getQuick(i).getAst().position, fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } entityColumnFilter.of(writerMetadata.getColumnCount()); copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, entityColumnFilter); } try (RecordCursor cursor = factory.getCursor(executionContext)) { try { if (writerTimestampIndex == -1) { copyUnordered(cursor, writer, copier); } else { copyOrdered(writer, cursor, copier, writerTimestampIndex); } } catch (CairoException e) { writer.rollback(); throw e; } } } return compiledQuery.ofInsertAsSelect(); } }
SqlCompiler implements Closeable { private CompiledQuery insertAsSelect(ExecutionModel executionModel, SqlExecutionContext executionContext) throws SqlException { final InsertModel model = (InsertModel) executionModel; final ExpressionNode name = model.getTableName(); tableExistsOrFail(name.position, name.token, executionContext); try (TableWriter writer = engine.getWriter(executionContext.getCairoSecurityContext(), name.token); RecordCursorFactory factory = generate(model.getQueryModel(), executionContext)) { final RecordMetadata cursorMetadata = factory.getMetadata(); final RecordMetadata writerMetadata = writer.getMetadata(); final int writerTimestampIndex = writerMetadata.getTimestampIndex(); final int cursorTimestampIndex = cursorMetadata.getTimestampIndex(); final int cursorColumnCount = cursorMetadata.getColumnCount(); if (writerTimestampIndex > -1 && cursorTimestampIndex == -1) { if (cursorColumnCount <= writerTimestampIndex) { throw SqlException.$(name.position, "select clause must provide timestamp column"); } else if (cursorMetadata.getColumnType(writerTimestampIndex) != ColumnType.TIMESTAMP) { throw SqlException.$(name.position, "expected timestamp column but type is ").put(ColumnType.nameOf(cursorMetadata.getColumnType(writerTimestampIndex))); } } if (writerTimestampIndex > -1 && cursorTimestampIndex > -1 && writerTimestampIndex != cursorTimestampIndex) { throw SqlException.$(name.position, "nominated column of existing table (").put(writerTimestampIndex).put(") does not match nominated column in select query (").put(cursorTimestampIndex).put(')'); } final RecordToRowCopier copier; CharSequenceHashSet columnSet = model.getColumnSet(); final int columnSetSize = columnSet.size(); if (columnSetSize > 0) { listColumnFilter.clear(); for (int i = 0; i < columnSetSize; i++) { CharSequence columnName = columnSet.get(i); int index = writerMetadata.getColumnIndexQuiet(columnName); if (index == -1) { throw SqlException.invalidColumn(model.getColumnPosition(i), columnName); } int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(index); if (isAssignableFrom(toType, fromType)) { listColumnFilter.add(index); } else { throw SqlException.inconvertibleTypes( model.getColumnPosition(i), fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } } copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, listColumnFilter); } else { final int n = writerMetadata.getColumnCount(); if (n > cursorMetadata.getColumnCount()) { throw SqlException.$(model.getSelectKeywordPosition(), "not enough columns selected"); } for (int i = 0; i < n; i++) { int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(i); if (isAssignableFrom(toType, fromType)) { continue; } assert i < model.getQueryModel().getBottomUpColumns().size(); throw SqlException.inconvertibleTypes( model.getQueryModel().getBottomUpColumns().getQuick(i).getAst().position, fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } entityColumnFilter.of(writerMetadata.getColumnCount()); copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, entityColumnFilter); } try (RecordCursor cursor = factory.getCursor(executionContext)) { try { if (writerTimestampIndex == -1) { copyUnordered(cursor, writer, copier); } else { copyOrdered(writer, cursor, copier, writerTimestampIndex); } } catch (CairoException e) { writer.rollback(); throw e; } } } return compiledQuery.ofInsertAsSelect(); } SqlCompiler(CairoEngine engine);  SqlCompiler(CairoEngine engine, @Nullable MessageBus messageBus, @Nullable FunctionFactoryCache functionFactoryCache); }
SqlCompiler implements Closeable { private CompiledQuery insertAsSelect(ExecutionModel executionModel, SqlExecutionContext executionContext) throws SqlException { final InsertModel model = (InsertModel) executionModel; final ExpressionNode name = model.getTableName(); tableExistsOrFail(name.position, name.token, executionContext); try (TableWriter writer = engine.getWriter(executionContext.getCairoSecurityContext(), name.token); RecordCursorFactory factory = generate(model.getQueryModel(), executionContext)) { final RecordMetadata cursorMetadata = factory.getMetadata(); final RecordMetadata writerMetadata = writer.getMetadata(); final int writerTimestampIndex = writerMetadata.getTimestampIndex(); final int cursorTimestampIndex = cursorMetadata.getTimestampIndex(); final int cursorColumnCount = cursorMetadata.getColumnCount(); if (writerTimestampIndex > -1 && cursorTimestampIndex == -1) { if (cursorColumnCount <= writerTimestampIndex) { throw SqlException.$(name.position, "select clause must provide timestamp column"); } else if (cursorMetadata.getColumnType(writerTimestampIndex) != ColumnType.TIMESTAMP) { throw SqlException.$(name.position, "expected timestamp column but type is ").put(ColumnType.nameOf(cursorMetadata.getColumnType(writerTimestampIndex))); } } if (writerTimestampIndex > -1 && cursorTimestampIndex > -1 && writerTimestampIndex != cursorTimestampIndex) { throw SqlException.$(name.position, "nominated column of existing table (").put(writerTimestampIndex).put(") does not match nominated column in select query (").put(cursorTimestampIndex).put(')'); } final RecordToRowCopier copier; CharSequenceHashSet columnSet = model.getColumnSet(); final int columnSetSize = columnSet.size(); if (columnSetSize > 0) { listColumnFilter.clear(); for (int i = 0; i < columnSetSize; i++) { CharSequence columnName = columnSet.get(i); int index = writerMetadata.getColumnIndexQuiet(columnName); if (index == -1) { throw SqlException.invalidColumn(model.getColumnPosition(i), columnName); } int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(index); if (isAssignableFrom(toType, fromType)) { listColumnFilter.add(index); } else { throw SqlException.inconvertibleTypes( model.getColumnPosition(i), fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } } copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, listColumnFilter); } else { final int n = writerMetadata.getColumnCount(); if (n > cursorMetadata.getColumnCount()) { throw SqlException.$(model.getSelectKeywordPosition(), "not enough columns selected"); } for (int i = 0; i < n; i++) { int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(i); if (isAssignableFrom(toType, fromType)) { continue; } assert i < model.getQueryModel().getBottomUpColumns().size(); throw SqlException.inconvertibleTypes( model.getQueryModel().getBottomUpColumns().getQuick(i).getAst().position, fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } entityColumnFilter.of(writerMetadata.getColumnCount()); copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, entityColumnFilter); } try (RecordCursor cursor = factory.getCursor(executionContext)) { try { if (writerTimestampIndex == -1) { copyUnordered(cursor, writer, copier); } else { copyOrdered(writer, cursor, copier, writerTimestampIndex); } } catch (CairoException e) { writer.rollback(); throw e; } } } return compiledQuery.ofInsertAsSelect(); } SqlCompiler(CairoEngine engine);  SqlCompiler(CairoEngine engine, @Nullable MessageBus messageBus, @Nullable FunctionFactoryCache functionFactoryCache); static void configureLexer(GenericLexer lexer); static boolean isAssignableFrom(int to, int from); @Override void close(); @NotNull CompiledQuery compile(@NotNull CharSequence query, @NotNull SqlExecutionContext executionContext); CairoEngine getEngine(); }
SqlCompiler implements Closeable { private CompiledQuery insertAsSelect(ExecutionModel executionModel, SqlExecutionContext executionContext) throws SqlException { final InsertModel model = (InsertModel) executionModel; final ExpressionNode name = model.getTableName(); tableExistsOrFail(name.position, name.token, executionContext); try (TableWriter writer = engine.getWriter(executionContext.getCairoSecurityContext(), name.token); RecordCursorFactory factory = generate(model.getQueryModel(), executionContext)) { final RecordMetadata cursorMetadata = factory.getMetadata(); final RecordMetadata writerMetadata = writer.getMetadata(); final int writerTimestampIndex = writerMetadata.getTimestampIndex(); final int cursorTimestampIndex = cursorMetadata.getTimestampIndex(); final int cursorColumnCount = cursorMetadata.getColumnCount(); if (writerTimestampIndex > -1 && cursorTimestampIndex == -1) { if (cursorColumnCount <= writerTimestampIndex) { throw SqlException.$(name.position, "select clause must provide timestamp column"); } else if (cursorMetadata.getColumnType(writerTimestampIndex) != ColumnType.TIMESTAMP) { throw SqlException.$(name.position, "expected timestamp column but type is ").put(ColumnType.nameOf(cursorMetadata.getColumnType(writerTimestampIndex))); } } if (writerTimestampIndex > -1 && cursorTimestampIndex > -1 && writerTimestampIndex != cursorTimestampIndex) { throw SqlException.$(name.position, "nominated column of existing table (").put(writerTimestampIndex).put(") does not match nominated column in select query (").put(cursorTimestampIndex).put(')'); } final RecordToRowCopier copier; CharSequenceHashSet columnSet = model.getColumnSet(); final int columnSetSize = columnSet.size(); if (columnSetSize > 0) { listColumnFilter.clear(); for (int i = 0; i < columnSetSize; i++) { CharSequence columnName = columnSet.get(i); int index = writerMetadata.getColumnIndexQuiet(columnName); if (index == -1) { throw SqlException.invalidColumn(model.getColumnPosition(i), columnName); } int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(index); if (isAssignableFrom(toType, fromType)) { listColumnFilter.add(index); } else { throw SqlException.inconvertibleTypes( model.getColumnPosition(i), fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } } copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, listColumnFilter); } else { final int n = writerMetadata.getColumnCount(); if (n > cursorMetadata.getColumnCount()) { throw SqlException.$(model.getSelectKeywordPosition(), "not enough columns selected"); } for (int i = 0; i < n; i++) { int fromType = cursorMetadata.getColumnType(i); int toType = writerMetadata.getColumnType(i); if (isAssignableFrom(toType, fromType)) { continue; } assert i < model.getQueryModel().getBottomUpColumns().size(); throw SqlException.inconvertibleTypes( model.getQueryModel().getBottomUpColumns().getQuick(i).getAst().position, fromType, cursorMetadata.getColumnName(i), toType, writerMetadata.getColumnName(i) ); } entityColumnFilter.of(writerMetadata.getColumnCount()); copier = assembleRecordToRowCopier(asm, cursorMetadata, writerMetadata, entityColumnFilter); } try (RecordCursor cursor = factory.getCursor(executionContext)) { try { if (writerTimestampIndex == -1) { copyUnordered(cursor, writer, copier); } else { copyOrdered(writer, cursor, copier, writerTimestampIndex); } } catch (CairoException e) { writer.rollback(); throw e; } } } return compiledQuery.ofInsertAsSelect(); } SqlCompiler(CairoEngine engine);  SqlCompiler(CairoEngine engine, @Nullable MessageBus messageBus, @Nullable FunctionFactoryCache functionFactoryCache); static void configureLexer(GenericLexer lexer); static boolean isAssignableFrom(int to, int from); @Override void close(); @NotNull CompiledQuery compile(@NotNull CharSequence query, @NotNull SqlExecutionContext executionContext); CairoEngine getEngine(); static final ObjList<String> sqlControlSymbols; }