Merge lp:~mmcm/akiban-server/parse-boolean into lp:~akiban-technologies/akiban-server/trunk

Proposed by Mike McMahon
Status: Merged
Approved by: Thomas Jones-Low
Approved revision: 2602
Merged at revision: 2601
Proposed branch: lp:~mmcm/akiban-server/parse-boolean
Merge into: lp:~akiban-technologies/akiban-server/trunk
Diff against target: 81 lines (+34/-21)
2 files modified
src/main/java/com/akiban/server/types3/TParsers.java (+28/-20)
src/test/java/com/akiban/server/types3/BooleanParserTest.java (+6/-1)
To merge this branch: bzr merge lp:~mmcm/akiban-server/parse-boolean
Reviewer Review Type Date Requested Status
Nathan Williams Approve
Mike McMahon Needs Resubmitting
Akiban Build User Needs Fixing
Thomas Jones-Low Approve
Review via email: mp+155086@code.launchpad.net

Description of the change

Although the recent change to expose AkBool included extensive new tests, they missed the simple case of boolean string literal, such as 'true', which was ending up as false.

Additionally, ActiveRecord sends 't' and 'f' (see lib/active_record/connection_adapters/abstract/quoting.rb and note that even redefining quoted_true and quoted_false isn't enough because they're also in type_cast), so we need those, too.

To post a comment you must log in.
Revision history for this message
Thomas Jones-Low (tjoneslo) wrote :

True and False for the server.

review: Approve
Revision history for this message
Nathan Williams (nwilliams) wrote :

Note that they weren't missed. It was left as-is for MySQL compat.

Perhaps that isn't important though.

Revision history for this message
Akiban Build User (build-akiban) wrote :

There were 2 failures during build/test:

* job server-build failed at build number 3928: http://172.16.20.104:8080/job/server-build/3928/

* view must-pass failed: server-build is yellow

review: Needs Fixing
Revision history for this message
Mike McMahon (mmcm) wrote :

A column declared BOOLEAN via the adapter will still be TINYINT, won't it? So conversions involving this type won't apply. Or did I misunderstand the earlier change?

lp:~mmcm/akiban-server/parse-boolean updated
2602. By Mike McMahon

Make the test more obvious.

Revision history for this message
Mike McMahon (mmcm) wrote :

Like Nathan said, there was an explicit test for one of the now incompatible cases.

So, clean up to make it much more explicit for the future what we are proposing to do.

review: Needs Resubmitting
Revision history for this message
Nathan Williams (nwilliams) wrote :

> A column declared BOOLEAN via the adapter will still be
> TINYINT, won't it? So conversions involving this type
> won't apply.

Conversion from string to BOOLEAN, such as WHERE <varchar>. Silly edge case, of course.

The rest of the compatible parse (e.g. 1.asdf = true) is funny, but no need to redo everything right now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main/java/com/akiban/server/types3/TParsers.java'
2--- src/main/java/com/akiban/server/types3/TParsers.java 2013-03-22 20:05:57 +0000
3+++ src/main/java/com/akiban/server/types3/TParsers.java 2013-03-23 13:38:21 +0000
4@@ -33,31 +33,39 @@
5 @Override
6 public void parse(TExecutionContext context, PValueSource source, PValueTarget target)
7 {
8- // parse source is a string representing a number-ish, where '0' is false, any other integer is true.
9- // We're looking for an optional negative, followed by an optional dot, followed by any number of digits,
10- // followed by anything. If any of those digits is not 0, the result is true; otherwise it's false.
11 String s = source.getString();
12- boolean negativeAllowed = true;
13- boolean periodAllowed = true;
14 boolean result = false;
15- for (int i = 0, len = s.length(); i < len; ++i) {
16- char c = s.charAt(i);
17- if (negativeAllowed && c == '-') {
18- negativeAllowed = false;
19- }
20- else if (periodAllowed && c == '.') {
21- periodAllowed = false;
22- negativeAllowed = false;
23- }
24- else if (Character.isDigit(c)) {
25- if (c != '0') {
26- result = true;
27+ if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t")) {
28+ result = true;
29+ }
30+ else if (s.equalsIgnoreCase("false") || s.equalsIgnoreCase("f")) {
31+ result = false;
32+ }
33+ else {
34+ // parse source is a string representing a number-ish, where '0' is false, any other integer is true.
35+ // We're looking for an optional negative, followed by an optional dot, followed by any number of digits,
36+ // followed by anything. If any of those digits is not 0, the result is true; otherwise it's false.
37+ boolean negativeAllowed = true;
38+ boolean periodAllowed = true;
39+ for (int i = 0, len = s.length(); i < len; ++i) {
40+ char c = s.charAt(i);
41+ if (negativeAllowed && c == '-') {
42+ negativeAllowed = false;
43+ }
44+ else if (periodAllowed && c == '.') {
45+ periodAllowed = false;
46+ negativeAllowed = false;
47+ }
48+ else if (Character.isDigit(c)) {
49+ if (c != '0') {
50+ result = true;
51+ break;
52+ }
53+ }
54+ else {
55 break;
56 }
57 }
58- else {
59- break;
60- }
61 }
62 target.putBool(result);
63 }
64
65=== modified file 'src/test/java/com/akiban/server/types3/BooleanParserTest.java'
66--- src/test/java/com/akiban/server/types3/BooleanParserTest.java 2013-03-22 20:05:57 +0000
67+++ src/test/java/com/akiban/server/types3/BooleanParserTest.java 2013-03-23 13:38:21 +0000
68@@ -55,7 +55,12 @@
69 param(builder, "a1", false); // MySQL doesn't believe in steak sauce
70 param(builder, "0", false);
71 param(builder, "0.0", false);
72- param(builder, "true", false);
73+
74+ param(builder, "false", false);
75+ param(builder, "f", false);
76+ // Following are not MySQL compatible, but required for ActiveRecord.
77+ param(builder, "true", true);
78+ param(builder, "t", true);
79
80 return builder.asList();
81 }

Subscribers

People subscribed via source and target branches