Skip to content

Commit

Permalink
Release v1.11.4
Browse files Browse the repository at this point in the history
- Fix the following bug.
  - NOT IN operator returns incorrect result in some cases.
  • Loading branch information
mithrandie committed Jun 1, 2019
2 parents f0425c3 + 3eaf6dc commit 5c49455
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 156 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Change Log

## Version 1.11.4

Released on Jun 1, 2019

- Fix the following bug.
- NOT IN operator returns incorrect result in some cases.

## Version 1.11.3

Released on Jun 1, 2019

- Implement FETCH clause that can be used in place of LIMIT clause in SELECT query.
- Fix the following bug.
- FALSE takes precedence over UNKNOWN in NOT IN expression.
- FALSE takes precedence over UNKNOWN in NOT IN operation.

## Version 1.11.2

Expand Down
34 changes: 18 additions & 16 deletions docs/_posts/2006-01-02-comparison-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ _string_
_pattern_
: [string]({{ '/reference/value.html#string' | relative_url }})

Return TRUE if a _string_ matches a _pattern_, otherwise return FALSE.
Returns TRUE if _string_ matches _pattern_, otherwise returns FALSE.
If _string_ is a null, return UNKNOWN.

In a pattern, following special characters are used.
In _pattern_, following special characters can be used.

%
: any number of characters.
: any number of characters

_ (U+005F Low Line)
: exactly one character
Expand Down Expand Up @@ -162,9 +162,11 @@ _single_field_subquery_
_multiple_fields_subquery_
: [subquery]({{ '/reference/value.html#subquery' | relative_url }})

Check if a _value_ or _row_value_ is in within a set of _values_ or a result set of _select_query_.
Check if _value_ or _row_value_ is in within the set of _values_ or the result set of _select_query_.

A IN operation is equivalent to a [ANY](#any) operation that _relational_operator_ is specified as "=".
_IN_ is equivalent to [ANY](#any) operator that _relational_operator_ is specified as "=".

_NOT IN_ is equivalent to [ALL](#all) operator that _relational_operator_ is specified as "<>".

## ANY
{: #any}
Expand Down Expand Up @@ -192,12 +194,12 @@ _single_field_subquery_
_multiple_fields_subquery_
: [subquery]({{ '/reference/value.html#subquery' | relative_url }})

Compare a _value_ or _row_value_ to each listed _values_ or each records retrieved by _select_query_.
If any of comparison results is TRUE, return TRUE.
If there is no TRUE result and there is at least one UNKNOWN result, return UNKNOWN.
Otherwise return FALSE.
Compare _value_ or _row_value_ to each listed _values_ or each records retrieved by _select_query_.
If any of comparison results is TRUE, returns TRUE.
If there is no TRUE result and there is at least one UNKNOWN result, returns UNKNOWN.
Otherwise returns FALSE.

If _select_query_ returns no record, return FALSE.
If _select_query_ returns no record, returns FALSE.

## ALL
{: #all}
Expand Down Expand Up @@ -225,12 +227,12 @@ _single_field_subquery_
_multiple_fields_subquery_
: [subquery]({{ '/reference/value.html#subquery' | relative_url }})

Compare a _value_ or _row_value_ to every listed _values_ or each records retrieved by _select_query_.
If any of comparison results is FALSE, return FALSE.
If there is no FALSE result and there is at least one UNKNOWN result, return UNKNOWN.
Otherwise return TRUE.
Compare _value_ or _row_value_ to every listed _values_ or each records retrieved by _select_query_.
If any of comparison results is FALSE, returns FALSE.
If there is no FALSE result and there is at least one UNKNOWN result, returns UNKNOWN.
Otherwise returns TRUE.

If _select_query_ returns no record, return TRUE.
If _select_query_ returns no record, returns TRUE.

## Exists
{: #exists}
Expand All @@ -242,4 +244,4 @@ EXISTS (select_query)
_select_query_
: [Select Query]({{ '/reference/select-query.html' | relative_url }})

Return TRUE if a _select_query_ returns at least one record, otherwise return FALSE.
Returns TRUE if a _select_query_ returns at least one record, otherwise returns FALSE.
9 changes: 8 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ title: Change Log - csvq

# Change Log

## Version 1.11.4

Released on Jun 1, 2019

- Fix the following bug.
- NOT IN operator returns incorrect result in some cases.

## Version 1.11.3

Released on Jun 1, 2019

- Implement FETCH clause that can be used in place of LIMIT clause in SELECT query.
- Fix the following bug.
- FALSE takes precedence over UNKNOWN in NOT IN expression.
- FALSE takes precedence over UNKNOWN in NOT IN operation.

## Version 1.11.2

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ In the multiple operations, you can use variables, cursors, temporary tables, an

## Latest Release

Version 1.11.3
Version 1.11.4
: Released on Jun 1, 2019

<a class="waves-effect waves-light btn" href="https://github.com/mithrandie/csvq/releases/tag/v1.11.3">
<a class="waves-effect waves-light btn" href="https://github.com/mithrandie/csvq/releases/tag/v1.11.4">
<i class="material-icons left">file_download</i>download
</a>

Expand Down
6 changes: 3 additions & 3 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>https://mithrandie.github.io/csvq/</loc>
<lastmod>2019-06-01T05:47:33+00:00</lastmod>
<lastmod>2019-06-01T12:10:32+00:00</lastmod>
</url>
<url>
<loc>https://mithrandie.github.io/csvq/reference.html</loc>
Expand Down Expand Up @@ -126,7 +126,7 @@
</url>
<url>
<loc>https://mithrandie.github.io/csvq/reference/comparison-operators.html</loc>
<lastmod>2018-11-24T20:56:09+00:00</lastmod>
<lastmod>2019-06-01T12:02:27+00:00</lastmod>
</url>
<url>
<loc>https://mithrandie.github.io/csvq/reference/logic-operators.html</loc>
Expand Down Expand Up @@ -178,7 +178,7 @@
</url>
<url>
<loc>https://mithrandie.github.io/csvq/changelog.html</loc>
<lastmod>2019-06-01T05:47:33+00:00</lastmod>
<lastmod>2019-06-01T12:10:32+00:00</lastmod>
</url>
<url>
<loc>https://mithrandie.github.io/csvq/license.html</loc>
Expand Down
23 changes: 0 additions & 23 deletions lib/query/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,29 +158,6 @@ func InRowValueList(rowValue value.RowValue, list []value.RowValue, matchType in
}
}

func NotInRowValueList(rowValue value.RowValue, list []value.RowValue, datetimeFormats []string) (ternary.Value, error) {
results := make([]ternary.Value, len(list))

for i, v := range list {
t, err := value.CompareRowValues(rowValue, v, "=", datetimeFormats)
if err != nil {
return ternary.FALSE, NewRowValueLengthInListError(i)
}
results[i] = t
}

ret := ternary.Not(ternary.Any(results))
if ret == ternary.FALSE {
for _, v := range results {
if v == ternary.UNKNOWN {
ret = ternary.UNKNOWN
break
}
}
}
return ret, nil
}

func Any(rowValue value.RowValue, list []value.RowValue, operator string, datetimeFormats []string) (ternary.Value, error) {
return InRowValueList(rowValue, list, parser.ANY, operator, datetimeFormats)
}
Expand Down
108 changes: 0 additions & 108 deletions lib/query/comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,111 +236,3 @@ func TestInRowValueList(t *testing.T) {
}
}
}

var notInRowValueListTests = []struct {
LHS value.RowValue
List []value.RowValue
Result ternary.Value
Error string
}{
{
LHS: value.RowValue{
value.NewInteger(1),
value.NewInteger(2),
value.NewInteger(3),
},
List: []value.RowValue{
{
value.NewInteger(2),
value.NewInteger(3),
value.NewInteger(4),
},
{
value.NewInteger(4),
value.NewInteger(5),
value.NewInteger(6),
},
},
Result: ternary.TRUE,
},
{
LHS: value.RowValue{
value.NewInteger(1),
value.NewInteger(2),
value.NewInteger(3),
},
List: []value.RowValue{
{
value.NewInteger(1),
value.NewInteger(2),
value.NewInteger(3),
},
{
value.NewInteger(4),
value.NewInteger(5),
value.NewInteger(6),
},
},
Result: ternary.FALSE,
},
{
LHS: value.RowValue{
value.NewInteger(1),
value.NewInteger(2),
value.NewInteger(3),
},
List: []value.RowValue{
{
value.NewInteger(1),
value.NewNull(),
value.NewInteger(3),
},
{
value.NewInteger(4),
value.NewInteger(5),
value.NewInteger(6),
},
},
Result: ternary.UNKNOWN,
},
{
LHS: value.RowValue{
value.NewInteger(1),
value.NewInteger(2),
value.NewInteger(3),
},
List: []value.RowValue{
{
value.NewInteger(1),
value.NewInteger(2),
value.NewInteger(3),
},
{
value.NewInteger(1),
value.NewInteger(3),
},
},
Error: "row value length does not match at index 1",
},
}

func TestNotInRowValueList(t *testing.T) {
for _, v := range notInRowValueListTests {
r, err := NotInRowValueList(v.LHS, v.List, TestTx.Flags.DatetimeFormat)
if err != nil {
if len(v.Error) < 1 {
t.Errorf("unexpected error %q for (%s %s)", err, v.LHS, v.List)
} else if err.Error() != v.Error {
t.Errorf("error %q, want error %q for (%s %s)", err.Error(), v.Error, v.LHS, v.List)
}
continue
}
if 0 < len(v.Error) {
t.Errorf("no error, want error %q for (%s %s)", v.Error, v.LHS, v.List)
continue
}
if r != v.Result {
t.Errorf("result = %s, want %s for (%s %s)", r, v.Result, v.LHS, v.List)
}
}
}
2 changes: 1 addition & 1 deletion lib/query/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func evalIn(ctx context.Context, scope *ReferenceScope, expr parser.In) (value.P

var t ternary.Value
if expr.IsNegated() {
t, err = NotInRowValueList(val, list, scope.Tx.Flags.DatetimeFormat)
t, err = All(val, list, "<>", scope.Tx.Flags.DatetimeFormat)
} else {
t, err = Any(val, list, "=", scope.Tx.Flags.DatetimeFormat)
}
Expand Down
17 changes: 17 additions & 0 deletions lib/query/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,23 @@ var evaluateTests = []struct {
},
Negation: parser.Token{Token: parser.NOT, Literal: "not"},
},
Result: value.NewTernary(ternary.FALSE),
},
{
Name: "Not In UNKNOWN",
Expr: parser.In{
LHS: parser.NewIntegerValue(2),
Values: parser.RowValue{
Value: parser.ValueList{
Values: []parser.QueryExpression{
parser.NewIntegerValue(3),
parser.NewIntegerValue(4),
parser.NewNullValue(),
},
},
},
Negation: parser.Token{Token: parser.NOT, Literal: "not"},
},
Result: value.NewTernary(ternary.UNKNOWN),
},
{
Expand Down
2 changes: 1 addition & 1 deletion lib/query/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package query

var Version = "v1.11.3"
var Version = "v1.11.4"

0 comments on commit 5c49455

Please sign in to comment.