<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License"); 
	- you may not use this file except in compliance with the License. - You 
	may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 
	- - Unless required by applicable law or agreed to in writing, software - 
	distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT 
	WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the 
	License for the specific language governing permissions and - limitations 
	under the License. -->
<!DOCTYPE dble:rule SYSTEM "rule.dtd">
<dble:rule xmlns:dble="http://dble.cloud/">
    <tableRule name="sharding-by-enum">
        <rule>
            <columns>id</columns>
            <algorithm>enum</algorithm>
        </rule>
    </tableRule>

    <tableRule name="sharding-by-range">
        <rule>
            <columns>id</columns>
            <algorithm>rangeLong</algorithm>
        </rule>
    </tableRule>

    <tableRule name="sharding-by-hash">
        <rule>
            <columns>id</columns>
            <algorithm>hashLong</algorithm>
        </rule>
    </tableRule>

    <tableRule name="sharding-by-mod">
        <rule>
            <columns>id</columns>
            <algorithm>hashmod</algorithm>
        </rule>
    </tableRule>

    <tableRule name="sharding-by-hash-str">
        <rule>
            <columns>id</columns>
            <algorithm>hashString</algorithm>
        </rule>
    </tableRule>

    <tableRule name="sharding-by-date">
        <rule>
            <columns>calldate</columns>
            <algorithm>partbydate</algorithm>
        </rule>
    </tableRule>

    <tableRule name="sharding-by-pattern">
        <rule>
            <columns>id</columns>
            <algorithm>pattern</algorithm>
        </rule>
    </tableRule>


    <!-- 枚举方式分区 -->
    <function name="enum"
              class="com.actiontech.dble.route.function.PartitionByFileMap">
        <property name="mapFile">partition-hash-int.txt</property>
        <property name="defaultNode">0</property><!--默认为-1,数据范围超出则报错-->
        <property name="type">0</property><!--默认为0 表示key为数字类型，如果是其他类型，请设为其他值-->
    </function>

    <!-- 数字范围方式分区 -->
    <function name="rangeLong"
              class="com.actiontech.dble.route.function.AutoPartitionByLong">
        <property name="mapFile">autopartition-long.txt</property>
        <property name="defaultNode">0</property><!--默认为-1,数据范围超出则报错-->
    </function>

    <!-- 固定Hash 分区,当partitionLength全为1时，退化为求模分区-->
    <!--MAX(sum(count*length[i]) must not more then 1024-->
    <function name="hashLong" class="com.actiontech.dble.route.function.PartitionByLong">
        <property name="partitionCount">8</property>
        <property name="partitionLength">128</property>
        <!-- <property name="partitionCount">2,3</property>
        <property name="partitionLength">4,5</property>-->
    </function>

    <!-- 对8求模-->
    <function name="hashmod" class="com.actiontech.dble.route.function.PartitionByLong">
        <property name="partitionCount">8</property>
        <property name="partitionLength">1</property>
    </function>

    <!-- 固定Hash 分区 ，string 类型-->
    <function name="hashString" class="com.actiontech.dble.route.function.PartitionByString">
        <property name="partitionCount">8</property>
        <property name="partitionLength">128</property>
        <property name="hashSlice">0:2</property>
        <!--<property name="hashSlice">-4:0</property> -->
    </function>

    <!-- 按日期分区 -->
    <!--四种情况讨论
    1.设置了sEndDate和defaultNode: 小于sBeginDate 进defaultNode，大于sEndDate求模
    2.设置了sEndDate，不设置defaultNode:小于sBeginDate报错，大于sEndDate求模
    3.不设置sEndDate，设置defaultNode：小于sBeginDate 进defaultNode，大于sBeginDate+ 节点数*sPartionDay-1 会在算法外层报错(期望是进defaultNode，但算法本身无法控制)
    4.不设置sEndDate和defaultNode: 小于sBeginDate报错，大于sBeginDate+ 节点数*sPartionDay-1 会在外层报错
     -->
    <function name="partbydate"
              class="com.actiontech.dble.route.function.PartitionByDate">
        <property name="dateFormat">yyyy-MM-dd</property>
        <property name="sBeginDate">2015-01-01</property>
        <property name="sEndDate">2015-01-31
        </property> <!--sEndDate可不设置，如设置，请自行计算 sEndDate = sBeginDate+ 节点数*sPartionDay-1 -->
        <property name="sPartionDay">10</property>
        <property name="defaultNode">0</property><!--默认为-1 ,若为-1 时,小于sBeginDate日期直接报错 -->
    </function>

    <!-- 模式方式分区 -->
    <function name="pattern"
              class="com.actiontech.dble.route.function.PartitionByPattern">
        <property name="mapFile">partition-pattern.txt</property>
        <property name="patternValue">1024</property>
        <property name="defaultNode">0</property><!--默认为-1,数据范围超出则报错-->
    </function>


</dble:rule>
