[ 
https://issues.apache.org/jira/browse/CALCITE-5832?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17741889#comment-17741889
 ] 

Ulrich Kramer commented on CALCITE-5832:
----------------------------------------

This is the incomplete graphviz output. The {{CyclicMetadataException}} is also 
thrown during {{dump}}

{code}
digraph G {
        root [style=filled,label="Root"];
        subgraph cluster0{
                label="Set 0 RecordType(INTEGER contentViewsCount, BOOLEAN 
isExpired, VARCHAR(100) metadataPreviewUrl, VARCHAR(100) format, VARCHAR(100) 
description, VARCHAR(100) language, VARCHAR(100) assetTitle, VARCHAR(100) 
assetType, VARCHAR(100) contentType, VARCHAR(100) doi, VARCHAR(100) crmBpn)";
                rel1 [label="rel#1:JdbcTableScan\ntable=[BASEJDBC, 
T1]\nrows=100.0, cost={100.0 rows, 101.0 cpu, 0.0 io}",color=blue,shape=box]
                rel95 
[label="rel#95:JdbcToEnumerableConverter\ninput=RelSubset#61\nrows=100.0, 
cost={110.0 rows, 111.0 cpu, 0.0 io}",color=blue,shape=box]
                rel104 
[label="rel#104:AbstractConverter\ninput=RelSubset#96,convention=ENUMERABLE,sort=[9]\nrows=100.0,
 cost={inf}",shape=box]
                rel170 
[label="rel#170:LogicalSort\ninput=RelSubset#96,sort0=$9,dir0=ASC\nrows=100.0, 
cost={inf}",shape=box]
                rel251 
[label="rel#251:EnumerableSort\ninput=RelSubset#96,sort0=$9,dir0=ASC\nrows=100.0,
 cost={210.0 rows, 25899.953041533314 cpu, 0.0 io}",shape=box]
                rel252 
[label="rel#252:JdbcSort\ninput=RelSubset#61,sort0=$9,dir0=ASC\nrows=100.0, 
cost={190.0 rows, 23311.057737379982 cpu, 0.0 io}",color=blue,shape=box]
                rel361 
[label="rel#361:JdbcToEnumerableConverter\ninput=RelSubset#253\nrows=100.0, 
cost={200.0 rows, 23321.057737379982 cpu, 0.0 io}",color=blue,shape=box]
                subset61 [label="rel#61:RelSubset#0.JDBC.BASEJDBC.[]"]
                subset96 [label="rel#96:RelSubset#0.ENUMERABLE.[]"]
                subset103 [label="rel#103:RelSubset#0.ENUMERABLE.[9]"]
                subset171 [label="rel#171:RelSubset#0.NONE.[9]"]
                subset253 [label="rel#253:RelSubset#0.JDBC.BASEJDBC.[9]"]
                subset61 -> subset253;          subset96 -> subset103;  }
        subgraph cluster1{
                label="Set 1 RecordType(VARCHAR(100) doi, VARCHAR(100) 
industry)";
                rel3 [label="rel#3:JdbcTableScan\ntable=[BASEJDBC, 
T2]\nrows=100.0, cost={100.0 rows, 101.0 cpu, 0.0 io}",color=blue,shape=box]
                rel98 
[label="rel#98:JdbcToEnumerableConverter\ninput=RelSubset#62\nrows=100.0, 
cost={110.0 rows, 111.0 cpu, 0.0 io}",color=blue,shape=box]
                rel106 
[label="rel#106:AbstractConverter\ninput=RelSubset#99,convention=ENUMERABLE,sort=[0]\nrows=100.0,
 cost={inf}",shape=box]
                rel172 
[label="rel#172:LogicalSort\ninput=RelSubset#99,sort0=$0,dir0=ASC\nrows=100.0, 
cost={inf}",shape=box]
                rel254 
[label="rel#254:EnumerableSort\ninput=RelSubset#99,sort0=$0,dir0=ASC\nrows=100.0,
 cost={210.0 rows, 9321.340371976183 cpu, 0.0 io}",shape=box]
                rel255 
[label="rel#255:JdbcSort\ninput=RelSubset#62,sort0=$0,dir0=ASC\nrows=100.0, 
cost={190.0 rows, 8390.306334778565 cpu, 0.0 io}",color=blue,shape=box]
                rel363 
[label="rel#363:JdbcToEnumerableConverter\ninput=RelSubset#256\nrows=100.0, 
cost={200.0 rows, 8400.306334778565 cpu, 0.0 io}",color=blue,shape=box]
                subset62 [label="rel#62:RelSubset#1.JDBC.BASEJDBC.[]"]
                subset99 [label="rel#99:RelSubset#1.ENUMERABLE.[]"]
                subset105 [label="rel#105:RelSubset#1.ENUMERABLE.[0]"]
                subset173 [label="rel#173:RelSubset#1.NONE.[0]"]
                subset256 [label="rel#256:RelSubset#1.JDBC.BASEJDBC.[0]"]
                subset62 -> subset256;          subset99 -> subset105;  }
        subgraph cluster2{
                label="Set 2 RecordType(INTEGER contentViewsCount, BOOLEAN 
isExpired, VARCHAR(100) metadataPreviewUrl, VARCHAR(100) format, VARCHAR(100) 
description, VARCHAR(100) language, VARCHAR(100) assetTitle, VARCHAR(100) 
assetType, VARCHAR(100) contentType, VARCHAR(100) doi, VARCHAR(100) crmBpn, 
VARCHAR(100) doi0, VARCHAR(100) industry)";
                rel63 
[label="rel#63:LogicalJoin\nleft=RelSubset#61,right=RelSubset#62,condition==($9,
 $11),joinType=left\nrows=1585.0, cost={inf}",shape=box]
                rel101 
[label="rel#101:EnumerableHashJoin\nleft=RelSubset#96,right=RelSubset#99,condition==($9,
 $11),joinType=left\nrows=1585.0, cost={2365.517018598809 rows, 222.0 cpu, 0.0 
io}",shape=box]
                rel107 [label="rel#107:EnumerableMergeJoin.ENUMERABLE.[[9], 
[11]]\nleft=RelSubset#103,right=RelSubset#105,condition==($9, 
$11),joinType=left\nrows=1585.0, cost={2185.0 rows, 31721.364072158547 cpu, 0.0 
io}",shape=box]
                rel108 
[label="rel#108:JdbcJoin\nleft=RelSubset#61,right=RelSubset#62,condition==($9, 
$11),joinType=left\nrows=1585.0, cost={1785.0 rows, 202.0 cpu, 0.0 
io}",color=blue,shape=box]
                rel121 
[label="rel#121:AbstractConverter\ninput=RelSubset#102,convention=ENUMERABLE,sort=[12]\nrows=1585.0,
 cost={inf}",shape=box]
                rel176 
[label="rel#176:JdbcToEnumerableConverter\ninput=RelSubset#109\nrows=1585.0, 
cost={1943.5 rows, 360.5 cpu, 0.0 io}",color=blue,shape=box]
                rel179 
[label="rel#179:LogicalSort\ninput=RelSubset#102,sort0=$12,dir0=ASC\nrows=1585.0,
 cost={inf}",shape=box]
                rel257 
[label="rel#257:EnumerableSort\ninput=RelSubset#102,sort0=$12,dir0=ASC\nrows=1585.0,
 cost={3528.5 rows, 747804.8777794265 cpu, 0.0 io}",shape=box]
                rel258 
[label="rel#258:JdbcSort\ninput=RelSubset#109,sort0=$12,dir0=ASC\nrows=1585.0, 
cost={3211.5 rows, 672901.9400014839 cpu, 0.0 io}",color=blue,shape=box]
                rel365 
[label="rel#365:JdbcToEnumerableConverter\ninput=RelSubset#259\nrows=1585.0, 
cost={3370.0 rows, 673060.4400014839 cpu, 0.0 io}",color=blue,shape=box]
                subset64 [label="rel#64:RelSubset#2.NONE.[]"]
                subset102 [label="rel#102:RelSubset#2.ENUMERABLE.[]"]
                subset109 [label="rel#109:RelSubset#2.JDBC.BASEJDBC.[]"]
                subset120 [label="rel#120:RelSubset#2.ENUMERABLE.[12]"]
                subset180 [label="rel#180:RelSubset#2.NONE.[12]"]
                subset259 [label="rel#259:RelSubset#2.JDBC.BASEJDBC.[12]"]
                subset64 -> subset180;          subset102 -> subset120;         
subset109 -> subset259; }
        subgraph cluster3{
                label="Set 3 RecordType(VARCHAR(100) semaphoreId, VARCHAR(100) 
name, VARCHAR(100) industryId)";
                rel7 [label="rel#7:JdbcTableScan\ntable=[BASEJDBC, 
T3]\nrows=100.0, cost={100.0 rows, 101.0 cpu, 0.0 io}",color=blue,shape=box]
                rel111 
[label="rel#111:JdbcToEnumerableConverter\ninput=RelSubset#65\nrows=100.0, 
cost={110.0 rows, 111.0 cpu, 0.0 io}",color=blue,shape=box]
                subset65 [label="rel#65:RelSubset#3.JDBC.BASEJDBC.[]"]
                subset112 [label="rel#112:RelSubset#3.ENUMERABLE.[]"]
        }
        subgraph cluster4{
                label="Set 4 RecordType(VARCHAR(100) industry.semaphoreId, 
VARCHAR(100) industry.title)";
                rel66 
[label="rel#66:LogicalProject\ninput=RelSubset#65,inputs=0..1\nrows=100.0, 
cost={inf}",shape=box]
                rel113 
[label="rel#113:EnumerableProject\ninput=RelSubset#112,inputs=0..1\nrows=100.0, 
cost={210.0 rows, 311.0 cpu, 0.0 io}",shape=box]
                rel115 
[label="rel#115:JdbcProject\ninput=RelSubset#65,inputs=0..1\nrows=100.0, 
cost={180.0 rows, 261.0 cpu, 0.0 io}",color=blue,shape=box]
                rel123 
[label="rel#123:AbstractConverter\ninput=RelSubset#114,convention=ENUMERABLE,sort=[0]\nrows=100.0,
 cost={inf}",shape=box]
                rel178 
[label="rel#178:JdbcToEnumerableConverter\ninput=RelSubset#116\nrows=100.0, 
cost={190.0 rows, 271.0 cpu, 0.0 io}",color=blue,shape=box]
                rel181 
[label="rel#181:LogicalSort\ninput=RelSubset#114,sort0=$0,dir0=ASC\nrows=100.0, 
cost={inf}",shape=box]
                rel260 
[label="rel#260:EnumerableSort\ninput=RelSubset#114,sort0=$0,dir0=ASC\nrows=100.0,
 cost={290.0 rows, 9481.340371976183 cpu, 0.0 io}",shape=box]
                rel261 
[label="rel#261:JdbcSort\ninput=RelSubset#116,sort0=$0,dir0=ASC\nrows=100.0, 
cost={270.0 rows, 8550.306334778565 cpu, 0.0 io}",color=blue,shape=box]
                rel367 
[label="rel#367:JdbcToEnumerableConverter\ninput=RelSubset#262\nrows=100.0, 
cost={280.0 rows, 8560.306334778565 cpu, 0.0 io}",color=blue,shape=box]
                subset67 [label="rel#67:RelSubset#4.NONE.[]"]
                subset114 [label="rel#114:RelSubset#4.ENUMERABLE.[]"]
                subset116 [label="rel#116:RelSubset#4.JDBC.BASEJDBC.[]"]
                subset122 [label="rel#122:RelSubset#4.ENUMERABLE.[0]"]
                subset182 [label="rel#182:RelSubset#4.NONE.[0]"]
                subset262 [label="rel#262:RelSubset#4.JDBC.BASEJDBC.[0]"]
                subset114 -> subset122;         subset67 -> subset182;          
subset116 -> subset262; }
        subgraph cluster5{
                label="Set 5 RecordType(INTEGER contentViewsCount, BOOLEAN 
isExpired, VARCHAR(100) metadataPreviewUrl, VARCHAR(100) format, VARCHAR(100) 
description, VARCHAR(100) language, VARCHAR(100) assetTitle, VARCHAR(100) 
assetType, VARCHAR(100) contentType, VARCHAR(100) doi, VARCHAR(100) crmBpn, 
VARCHAR(100) doi0, VARCHAR(100) industry, VARCHAR(100) industry.semaphoreId, 
VARCHAR(100) industry.title)";
{code}

> CyclicMetadataException thrown in complex JOIN
> ----------------------------------------------
>
>                 Key: CALCITE-5832
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5832
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.34.0
>            Reporter: Ulrich Kramer
>            Priority: Major
>
> Adding the following unit test to {{JdbcAdapterTest}} reproduces the error
> {code:java}
>   @Test void testJdbcCyclicMetadata() throws Exception {
>     final String url = MultiJdbcSchemaJoinTest.TempDb.INSTANCE.getUrl();
>     Connection baseConnection = DriverManager.getConnection(url);
>     Statement baseStmt = baseConnection.createStatement();
>     baseStmt.execute("CREATE TABLE T1 (\n"
>         + "\"contentViewsCount\" INTEGER,\n" +
>         "\"isExpired\" BOOLEAN,\n" +
>         "\"metadataPreviewUrl\" VARCHAR(100),\n" +
>         "\"format\" VARCHAR(100),\n" +
>         "\"description\" VARCHAR(100),\n" +
>         "\"language\" VARCHAR(100),\n" +
>         "\"assetTitle\" VARCHAR(100),\n" +
>         "\"assetType\" VARCHAR(100),\n" +
>         "\"contentType\" VARCHAR(100),\n" +
>         "\"doi\" VARCHAR(100),\n" +
>         "\"crmBpn\" VARCHAR(100),\n" +
>         "PRIMARY KEY(\"doi\"))");
>     baseStmt.execute("CREATE TABLE T2 (\n"
>         + "\"doi\" VARCHAR(100),\n" +
>         "\"industry\" VARCHAR(100),\n" +
>         "PRIMARY KEY(\"doi\", \"industry\"))");
>     baseStmt.execute("CREATE TABLE T3 (\n"
>         + "\"semaphoreId\" VARCHAR(100),\n" +
>         "\"name\" VARCHAR(100),\n" +
>         "\"industryId\" VARCHAR(100),\n" +
>         "PRIMARY KEY(\"semaphoreId\"))");
>     baseStmt.execute("CREATE TABLE T4 (\n"
>         + "\"contentViewsCount\" INTEGER,\n" +
>         "\"CRM_Account_ID\" VARCHAR(100),\n" +
>         "\"CRM_Account_Name\" VARCHAR(100),\n" +
>         "PRIMARY KEY(\"CRM_Account_ID\"))");
>     baseStmt.close();
>     baseConnection.commit();
>     Properties info = new Properties();
>     info.put("model",
>         "inline:"
>             + "{\n"
>             + "  version: '1.0',\n"
>             + "  defaultSchema: 'BASEJDBC',\n"
>             + "  schemas: [\n"
>             + "     {\n"
>             + "       type: 'jdbc',\n"
>             + "       name: 'BASEJDBC',\n"
>             + "       jdbcDriver: '" + jdbcDriver.class.getName() + "',\n"
>             + "       jdbcUrl: '" + url + "',\n"
>             + "       jdbcCatalog: null,\n"
>             + "       jdbcSchema: null\n"
>             + "     }\n"
>             + "  ]\n"
>             + "}");
>     final Connection calciteConnection =
>         DriverManager.getConnection("jdbc:calcite:", info);
>     ResultSet rs = calciteConnection
>         .prepareStatement("SELECT \"_metadata.status\", \"doi\", 
> \"industry.title\", " +
>             "\"crm_account.crm_account_name\", \"assettitle\", 
> \"description\", \"assettype\", " +
>             "\"format\", \"contentviewscount\", \"metadatapreviewurl\", 
> \"language\", " +
>             "\"contenttype\", \"isexpired\" FROM (select\n" +
>             "  \"A\".\"contentViewsCount\" \"contentviewscount\",\n" +
>             "  \"A\".\"isExpired\" \"isexpired\",\n" +
>             "  \"A\".\"metadataPreviewUrl\" \"metadatapreviewurl\",\n" +
>             "  \"A\".\"format\" \"format\",\n" +
>             "  \"A\".\"description\" \"description\",\n" +
>             "  \"A\".\"language\" \"language\",\n" +
>             "  \"A\".\"assetTitle\" \"assettitle\",\n" +
>             "  \"A\".\"assetType\" \"assettype\",\n" +
>             "  \"A\".\"contentType\" \"contenttype\",\n" +
>             "  \"A\".\"doi\" \"doi\",\n" +
>             "  null \"_metadata.status\",\n" +
>             "  \"D\".\"industry.title\" \"industry.title\",\n" +
>             "  \"F\".\"crm_account.crm_account_name\" 
> \"crm_account.crm_account_name\"\n" +
>             "from \"T1\" \"A\"\n" +
>             "  left outer join \"T2\" \"B\"\n" +
>             "    on \"A\".\"doi\" = \"B\".\"doi\"\n" +
>             "  left outer join (\n" +
>             "    select\n" +
>             "      \"C\".\"semaphoreId\" \"industry.semaphoreId\",\n" +
>             "      \"C\".\"name\" \"industry.title\"\n" +
>             "    from \"T3\" \"C\"\n" +
>             "  ) \"D\"\n" +
>             "    on \"B\".\"industry\" = \"D\".\"industry.semaphoreId\"\n" +
>             "  left outer join (\n" +
>             "    select\n" +
>             "      \"E\".\"CRM_Account_ID\" 
> \"crm_account.CRM_Account_ID\",\n" +
>             "      \"E\".\"CRM_Account_Name\" 
> \"crm_account.crm_account_name\"\n" +
>             "    from \"T4\" \"E\"\n" +
>             "  ) \"F\"\n" +
>             "    on \"A\".\"crmBpn\" = \"F\".\"crm_account" +
>             ".CRM_Account_ID\")\n" +
>             "WHERE (\"isexpired\" = ?)\n" +
>             "AND (\"language\" IN (?, ?))\n" +
>             "AND (\"contenttype\" IN (?, ?))\n" +
>             "AND (\"doi\" IN (?))\n" +
>             "ORDER BY \"doi\" ASC\n" +
>             "LIMIT 500 OFFSET 0").executeQuery();
>     assertThat(rs.next(), is(true));
>     assertThat(rs.getObject(1), equalTo(20L));
>     assertThat(rs.next(), is(false));
>     rs.close();
>     calciteConnection.close();
>   }
> {code}
> The exception is triggered by adding the {{ORDER BY "doi"}} statement.
> I already tried several things. I caught the exception in 
> {{VolcanoPlanner::getCostOrInfinite}} and returned {{infCost}}. But this 
> leads to a {{StackOverflowException}} at another place.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to