<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>For English only</strong>, other languages will not accept.</p>
<p dir="auto">Before report a bug, make sure you have:</p>
<ul dir="auto">
<li>Searched open and closed <a href="https://github.com/apache/shardingsphere/issues">GitHub issues</a>.</li>
<li>Read documentation: <a href="https://shardingsphere.apache.org/document/current/en/overview" rel="nofollow">ShardingSphere Doc</a>.</li>
</ul>
<p dir="auto">Please pay attention on issues you submitted, because we maybe need more details.<br>
If no response anymore and we cannot reproduce it on current information, we will <strong>close it</strong>.</p>
<p dir="auto">Please answer these questions before submitting your issue. Thanks!</p>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<p dir="auto">master <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/apache/shardingsphere/commit/80e2fc202cb3fe24fd98d7c803808d25c195002d/hovercard" href="https://github.com/apache/shardingsphere/commit/80e2fc202cb3fe24fd98d7c803808d25c195002d"><tt>80e2fc2</tt></a></p>
<h3 dir="auto">Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?</h3>
<p dir="auto">Proxy</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">Create READWRITE_SPLITTING RULE and SHADOW RULE respectively with the same name, it should report duplicate data source</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="CREATE READWRITE_SPLITTING RULE duplicate_ds (
    WRITE_STORAGE_UNIT=ds_0,
    READ_STORAGE_UNITS(ds_1,ds_2),
    TYPE(NAME=&quot;random&quot;)
);
CREATE SHADOW RULE duplicate_ds (
  SOURCE=ds_0,
  SHADOW=ds_1,
  t_order(TYPE(NAME=&quot;SQL_HINT&quot;))
);
"><pre class="notranslate">CREATE READWRITE_SPLITTING RULE duplicate_ds (
    WRITE_STORAGE_UNIT<span class="pl-k">=</span>ds_0,
    READ_STORAGE_UNITS(ds_1,ds_2),
    TYPE(NAME<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>random<span class="pl-pds">"</span></span>)
);
CREATE SHADOW RULE duplicate_ds (
  SOURCE<span class="pl-k">=</span>ds_0,
  SHADOW<span class="pl-k">=</span>ds_1,
  t_order(TYPE(NAME<span class="pl-k">=</span><span class="pl-s"><span class="pl-pds">"</span>SQL_HINT<span class="pl-pds">"</span></span>))
);
</pre></div>
<h3 dir="auto">Actual behavior</h3>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Query OK, 0 rows affected"><pre class="notranslate">Query OK, <span class="pl-c1">0</span> rows affected</pre></div>
<h3 dir="auto">Reason analyze (If you can)</h3>
<p dir="auto">missing check</p>
<h2 dir="auto">Bug Report</h2>
<p dir="auto">i have raise this bug for twice, but the project owner close it twice.<br>
But it's not a duplicated and nonsensical issue, it's really a bug, please pay attention to the description as below.</p>
<div class="highlight highlight-source-sql notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="select * from t_order where create_time between '2018-01-01 00:00:00' and '2018-01-02 00:00:00'"><pre class="notranslate"><span class="pl-k">select</span> <span class="pl-k">*</span> <span class="pl-k">from</span> t_order <span class="pl-k">where</span> create_time between <span class="pl-s"><span class="pl-pds">'</span>2018-01-01 00:00:00<span class="pl-pds">'</span></span> <span class="pl-k">and</span> <span class="pl-s"><span class="pl-pds">'</span>2018-01-02 00:00:00<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">SQL like above is not supported, we use create_time for RangeShardingAlgorithm<br>
and we always get the wrong RangeShardingValue ( we expected Range ['2018-01-01 00:00:00', '2018-01-02 00:00:00'] bu we received Range [-1, -1] ), the column type of create_time is datetime.</p>
<p dir="auto">in the OrConditionFilter.java line 206, there is a bug</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="private com.google.common.base.Optional&lt;SQLExpression&gt; buildExpression(final SelectStatement selectStatement, final ExpressionSegment expressionSegment, final String sql,
                                                                           final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) {
        if (!(expressionSegment instanceof CommonExpressionSegment)) {
            new ExpressionFiller().fill(expressionSegment, selectStatement, sql, shardingRule, shardingTableMetaData);
            return com.google.common.base.Optional.absent();
        }
        CommonExpressionSegment commonExpressionSegment = (CommonExpressionSegment) expressionSegment;
        if (-1 &lt; commonExpressionSegment.getIndex()) {
            return com.google.common.base.Optional.&lt;SQLExpression&gt;of(new SQLPlaceholderExpression(commonExpressionSegment.getIndex()));
        }
       // it will always return SQLNumberExpression because there is a default value -1 for commonExpressionSegment.getValue()
        if (null != commonExpressionSegment.getValue()) {
            return com.google.common.base.Optional.&lt;SQLExpression&gt;of(new SQLNumberExpression(commonExpressionSegment.getValue()));
        }
        String expression = sql.substring(commonExpressionSegment.getStartPosition(), commonExpressionSegment.getEndPosition() + 1);
        return Optional.&lt;SQLExpression&gt;of(new SQLTextExpression(expression));
    }"><pre class="notranslate"><span class="pl-k">private</span> <span class="pl-smi">com</span>.<span class="pl-smi">google</span>.<span class="pl-smi">common</span>.<span class="pl-smi">base</span>.<span class="pl-smi">Optional</span>&lt;<span class="pl-smi">SQLExpression</span>&gt; <span class="pl-s1">buildExpression</span>(<span class="pl-k">final</span> <span class="pl-smi">SelectStatement</span> <span class="pl-s1">selectStatement</span>, <span class="pl-k">final</span> <span class="pl-smi">ExpressionSegment</span> <span class="pl-s1">expressionSegment</span>, <span class="pl-k">final</span> <span class="pl-smi">String</span> <span class="pl-s1">sql</span>,
                                                                           <span class="pl-k">final</span> <span class="pl-smi">ShardingRule</span> <span class="pl-s1">shardingRule</span>, <span class="pl-k">final</span> <span class="pl-smi">ShardingTableMetaData</span> <span class="pl-s1">shardingTableMetaData</span>) {
        <span class="pl-k">if</span> (!(<span class="pl-s1">expressionSegment</span> <span class="pl-k">instanceof</span> <span class="pl-smi">CommonExpressionSegment</span>)) {
            <span class="pl-k">new</span> <span class="pl-smi">ExpressionFiller</span>().<span class="pl-en">fill</span>(<span class="pl-s1">expressionSegment</span>, <span class="pl-s1">selectStatement</span>, <span class="pl-s1">sql</span>, <span class="pl-s1">shardingRule</span>, <span class="pl-s1">shardingTableMetaData</span>);
            <span class="pl-k">return</span> <span class="pl-s1">com</span>.<span class="pl-s1">google</span>.<span class="pl-s1">common</span>.<span class="pl-s1">base</span>.<span class="pl-s1">Optional</span>.<span class="pl-en">absent</span>();
        }
        <span class="pl-smi">CommonExpressionSegment</span> <span class="pl-s1">commonExpressionSegment</span> = (<span class="pl-smi">CommonExpressionSegment</span>) <span class="pl-s1">expressionSegment</span>;
        <span class="pl-k">if</span> (-<span class="pl-c1">1</span> &lt; <span class="pl-s1">commonExpressionSegment</span>.<span class="pl-en">getIndex</span>()) {
            <span class="pl-k">return</span> <span class="pl-s1">com</span>.<span class="pl-s1">google</span>.<span class="pl-s1">common</span>.<span class="pl-s1">base</span>.<span class="pl-s1">Optional</span>.&lt;<span class="pl-smi">SQLExpression</span>&gt;<span class="pl-en">of</span>(<span class="pl-k">new</span> <span class="pl-smi">SQLPlaceholderExpression</span>(<span class="pl-s1">commonExpressionSegment</span>.<span class="pl-en">getIndex</span>()));
        }
       <span class="pl-c">// it will always return SQLNumberExpression because there is a default value -1 for commonExpressionSegment.getValue()</span>
        <span class="pl-k">if</span> (<span class="pl-c1">null</span> != <span class="pl-s1">commonExpressionSegment</span>.<span class="pl-en">getValue</span>()) {
            <span class="pl-k">return</span> <span class="pl-s1">com</span>.<span class="pl-s1">google</span>.<span class="pl-s1">common</span>.<span class="pl-s1">base</span>.<span class="pl-s1">Optional</span>.&lt;<span class="pl-smi">SQLExpression</span>&gt;<span class="pl-en">of</span>(<span class="pl-k">new</span> <span class="pl-smi">SQLNumberExpression</span>(<span class="pl-s1">commonExpressionSegment</span>.<span class="pl-en">getValue</span>()));
        }
        <span class="pl-smi">String</span> <span class="pl-s1">expression</span> = <span class="pl-s1">sql</span>.<span class="pl-en">substring</span>(<span class="pl-s1">commonExpressionSegment</span>.<span class="pl-en">getStartPosition</span>(), <span class="pl-s1">commonExpressionSegment</span>.<span class="pl-en">getEndPosition</span>() + <span class="pl-c1">1</span>);
        <span class="pl-k">return</span> <span class="pl-smi">Optional</span>.&lt;<span class="pl-smi">SQLExpression</span>&gt;<span class="pl-en">of</span>(<span class="pl-k">new</span> <span class="pl-smi">SQLTextExpression</span>(<span class="pl-s1">expression</span>));
    }</pre></div>
<p dir="auto">the value field in CommonExpressionSegment has a default value -1. so it will be always consider as SQLNumberExpression.</p>
<p dir="auto">after i remove the default value -1 for field value in CommonExpressionSegment.java, it's ok.</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="public final class CommonExpressionSegment extends ExpressionWithAliasSegment
{

    private final int startPosition;

    private final int endPosition;

    private int index = -1;

    //remove the default value -1
    private Number value;
}"><pre class="notranslate"><span class="pl-k">public</span> <span class="pl-k">final</span> <span class="pl-k">class</span> <span class="pl-smi">CommonExpressionSegment</span> <span class="pl-k">extends</span> <span class="pl-smi">ExpressionWithAliasSegment</span>
{

    <span class="pl-k">private</span> <span class="pl-k">final</span> <span class="pl-smi">int</span> <span class="pl-s1">startPosition</span>;

    <span class="pl-k">private</span> <span class="pl-k">final</span> <span class="pl-smi">int</span> <span class="pl-s1">endPosition</span>;

    <span class="pl-k">private</span> <span class="pl-smi">int</span> <span class="pl-s1">index</span> = -<span class="pl-c1">1</span>;

    <span class="pl-c">//remove the default value -1</span>
    <span class="pl-k">private</span> <span class="pl-smi">Number</span> <span class="pl-s1">value</span>;
}</pre></div>
<p dir="auto">but the range value keep the single quote for the string like this:<br>
['2018-01-01 00:00:00', '2018-01-01 23:59:59']<br>
lowerEndpoint: '2018-01-01 00:00:00' upperEndpoint:  '2018-01-01 23:59:59'<br>
and what we expected is like this:<br>
[2018-01-01 00:00:00, 2018-01-01 23:59:59]<br>
lowerEndpoint: 2018-01-01 00:00:00 upperEndpoint:  2018-01-01 23:59:59</p>
<p dir="auto">the source code for RangeShardingAlgorithm is like this:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="public Collection&lt;String&gt; doSharding(Collection&lt;String&gt; availableTargetNames,  RangeShardingValue&lt;String&gt; value)"><pre class="notranslate"><span class="pl-k">public</span> <span class="pl-smi">Collection</span>&lt;<span class="pl-smi">String</span>&gt; <span class="pl-s1">doSharding</span>(<span class="pl-smi">Collection</span>&lt;<span class="pl-smi">String</span>&gt; <span class="pl-s1">availableTargetNames</span>,  <span class="pl-smi">RangeShardingValue</span>&lt;<span class="pl-smi">String</span>&gt; <span class="pl-s1">value</span>)</pre></div>
<h3 dir="auto">Which version of ShardingSphere did you use?</h3>
<p dir="auto">3.1.0</p>
<h3 dir="auto">Which project did you use? Sharding-JDBC or Sharding-Proxy?</h3>
<p dir="auto">Sharding-JDBC</p>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">supported</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">not supported</p>
<h3 dir="auto">Reason analyze (If you can)</h3>
<p dir="auto">as mentioned above</p>
<h3 dir="auto">Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.</h3>
<p dir="auto">as mentioned above</p>
<h3 dir="auto">Example codes for reproduce this issue (such as a github link).</h3>
<p dir="auto">as mentioned above</p>