Skip to content

Commit

Permalink
handle visitPredicate()
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaZero committed Feb 5, 2020
1 parent acce788 commit cb35c1b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 8 deletions.
Expand Up @@ -202,17 +202,17 @@ public ASTNode visitPredicate(final PredicateContext ctx) {
if (null != ctx.subquery()) {
return new SubquerySegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), ctx.subquery().getText());
}
if (null != ctx.IN()) {
if (null != ctx.IN() && null == ctx.NOT()) {
return createInSegment(ctx);
}
if (null != ctx.BETWEEN()) {
if (null != ctx.BETWEEN() && null == ctx.NOT()) {
return createBetweenSegment(ctx);
}
BitExprContext bitExpr = ctx.bitExpr(0);
if (null != bitExpr) {
if (1 == ctx.children.size()) {
BitExprContext bitExpr = ctx.bitExpr(0);
return createExpressionSegment(visit(bitExpr), ctx);
}
return createExpressionSegment(new LiteralValue(ctx.getText()), ctx);
return visitRemainPredicate(ctx);
}

@Override
Expand Down Expand Up @@ -554,9 +554,28 @@ private Collection<AndPredicate> getAndPredicates(final ASTNode astNode) {
if (astNode instanceof AndPredicate) {
return Collections.singleton((AndPredicate) astNode);
}
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add((PredicateSegment) astNode);
return Collections.singleton(andPredicate);
if (astNode instanceof PredicateSegment) {
AndPredicate andPredicate = new AndPredicate();
andPredicate.getPredicates().add((PredicateSegment) astNode);
return Collections.singleton(andPredicate);
}
return new LinkedList<>();
}

private ASTNode visitRemainPredicate(final PredicateContext ctx) {
for (BitExprContext each : ctx.bitExpr()) {
visit(each);
}
for (ExprContext each : ctx.expr()) {
visit(each);
}
for (SimpleExprContext each : ctx.simpleExpr()) {
visit(each);
}
if (null != ctx.predicate()) {
visit(ctx.predicate());
}
return new CommonExpressionSegment(ctx.start.getStartIndex(), ctx.stop.getStopIndex(), ctx.getText());
}

// TODO :FIXME, sql case id: insert_with_str_to_date
Expand Down
Expand Up @@ -108,4 +108,47 @@
<column-item name="item_id" />
</order-by>
</select>

<select sql-case-id="select_exclamation_equal_with_single_table" parameters="1">
<table name="t_order_item" start-index="14" stop-index="25" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where parameters-count="1" start-index="27" stop-index="44">
<and-predicate>
<predicate start-index="33" stop-index="44">
<column-left-value name="item_id" start-index="33" stop-index="39" />
<operator type="!=" />
<compare-right-value>
<parameter-marker-expression value="0" />
<literal-expression value="1" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
<order-by>
<column-item name="item_id" />
</order-by>
</select>

<select sql-case-id="select_not_in_with_single_table" parameters="100000, 100001">
<table name="t_order_item" start-index="14" stop-index="25" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where parameters-count="2" start-index="27" stop-index="77" literal-stop-index="87">
<!-- FIXME cannot parse IS NOT NULL -->
<!--<and-predicate>-->
<!--<predicate start-index="33" stop-index="51">-->
<!--<column-left-value name="item_id" start-index="33" stop-index="39" />-->
<!--</predicate>-->
<!--<predicate start-index="57" stop-index="77" literal-stop-index="87">-->
<!--<column-left-value name="item_id" start-index="57" stop-index="63" />-->
<!--</predicate>-->
<!--</and-predicate>-->
</where>
<order-by>
<column-item name="item_id" />
</order-by>
</select>
</sql-parser-test-cases>

0 comments on commit cb35c1b

Please sign in to comment.