Skip to content

cross join不能成功转换 #7

Open
@CembZy

Description

@CembZy

当cross join关联多个表的时候,不能成功转换。
test case:
Select * from table_c as v cross join table_b, table_c
转换后:
Select * from table_c as v cross join table_b, table_c

查看源码发现:

private boolean hasJoin( TJoinList joins )
	{
		if ( joins == null )
			return false;
		for ( int i = 0; i < joins.size( ); i++ )
		{
			if ( joins.getJoin( i ).getJoinItems( ) != null
					&& joins.getJoin( i ).getJoinItems( ).size( ) > 0 )
				return true;
		}
		return false;
	}

当cross join关联表的时候, joins.getJoin( i ).getJoinItems( )不为null,并且size大于0直接返回了true,导致没有进入cross join的转换方法中,但是cross join的getJoinItems( )实际上应该为null,因为joins.getJoin(i).getJoinItems().getJoinItem(j).toString()为null,cross join的hasJoin校验应该为false,缺少这一步判断,所以会导致直接不能转换,修改源码为:

private boolean hasJoin(TJoinList joins) {
        if (joins == null)
            return false;
        for (int i = 0; i < joins.size(); i++) {
            TJoinItemList joinItems = joins.getJoin(i).getJoinItems();
            if (null != joinItems && joinItems.size() > 0) {
                for (int j = 0; j < joinItems.size(); j++) {
                    if (null == joinItems.getJoinItem(j).toString()) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    }

即可。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions