<!--
  ~ Copyright (C) 2016-2023 ActionTech.
  ~ License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
  -->

<dble:sharding xmlns:dble="http://dble.cloud/" version="3.0">
    <schema name="cndb">
        <shardingTable name="offer" shardingNode="offer_dn$0-127" function="func" shardingColumn="member_id"/>
        <shardingTable name="offer_detail" shardingNode="detail_dn0,detail_dn$1-127" function="func2"
                       shardingColumn="offer_id" sqlRequiredSharding="false"/>
        <shardingTable name="offer_date" shardingNode="detail_dn0,detail_dn$1-127" function="by-date"
                       shardingColumn="col_date" sqlRequiredSharding="false"/>
        <globalTable name="independent" shardingNode="independent_dn$0-126,independent_dn127"/>
    </schema>

    <schema name="dbtest">
        <shardingTable name="tb2" shardingNode="dnTest2,dnTest3" function="func0" shardingColumn="id"/>
    </schema>

    <schema name="dubbo" shardingNode="dubbo_dn"/>

    <schema name="dubbo2" shardingNode="dn1">
        <globalTable name="company" shardingNode="dn1,dn2,dn3"/>
        <globalTable name="goods" shardingNode="dn1,dn2,dn3"/>
    </schema>

    <schema name="ignoreSchemaTest" shardingNode="cndb_dn"/>

    <schema name="config">
        <shardingTable name="offer" shardingNode="offer_dn$0-127" function="func" shardingColumn="member_id"
                       sqlRequiredSharding="true"/>
    </schema>

    <schema name="none_node_test">
        <shardingTable name="offer" shardingNode="offer_dn$0-127" function="func" shardingColumn="member_id"
                       sqlRequiredSharding="true"/>
    </schema>

    <schema name="solo1" shardingNode="solo1"/>
    <schema name="testdb" sqlMaxLimit="100">
        <singleTable name="a" shardingNode="dn1"/>
        <singleTable name="b" shardingNode="dn2"/>
        <singleTable name="c" shardingNode="dn3"/>
        <singleTable name="d" shardingNode="dn4"/>
        <singleTable name="e" shardingNode="dn4"/>
    </schema>
    <schema name="TESTDB" sqlMaxLimit="100">
        <shardingTable name="travelrecord" shardingNode="dn1,dn2,dn3" function="rang-long" shardingColumn="id"/>
        <!-- global table is auto cloned to all defined data nodes ,so can join
            with any table whose sharding node is in the same data node -->
        <globalTable name="company" shardingNode="dn1,dn2,dn3"/>
        <globalTable name="goods" shardingNode="dn1,dn2,dn3"/>
        <singleTable name="notpartionTable" shardingNode="dn1"/>
        <globalTable name="area" shardingNode="dn1,dn2,dn3"/>
        <shardingTable name="employee" shardingNode="dn1,dn2" function="func1" shardingColumn="sharding_id"/>
        <shardingTable name="customer" shardingNode="dn1,dn2" function="rang-long2" shardingColumn="id">
            <childTable name="orders" joinColumn="customer_id" parentColumn="id">
                <childTable name="order_items" joinColumn="order_id" parentColumn="id"/>
            </childTable>
            <childTable name="customer_addr" joinColumn="customer_id" parentColumn="id"/>
        </shardingTable>
        <singleTable name="globalsn" shardingNode="dn1"/>
    </schema>

    <schema name="mysqldb" sqlMaxLimit="100">
        <shardingTable name="autoslot" shardingNode="dn1,dn2" function="rang-long2" shardingColumn="id"/>
        <shardingTable name="offer" shardingNode="dn1,dn2" function="rang-long2" shardingColumn="id"/>
        <singleTable name="offer1" shardingNode="dn1"/>
    </schema>


    <shardingNode name="dn1" dbGroup="localhost1" database="db1"/>
    <shardingNode name="dn2" dbGroup="localhost1" database="db2"/>
    <shardingNode name="dn3" dbGroup="localhost1" database="db3"/>
    <shardingNode name="dn4" dbGroup="localhost1" database="db_4"/>
    <shardingNode name="cndb_dn" dbGroup="localhost1" database="db4"/>
    <shardingNode name="offer_dn$0-127" dbGroup="localhost1" database="db1$0-127"/>
    <shardingNode name="detail_dn$0-127" dbGroup="localhost1" database="db2$0-127"/>
    <shardingNode name="test_wild1$1-3" dbGroup="localhost$1-3" database="dbx"/>
    <shardingNode name="test_wild$1-6" dbGroup="localhost$1-3" database="db3$1-2"/>
    <shardingNode name="independent_dn$0-127" dbGroup="localhost1" database="db7_$0-127"/>
    <shardingNode name="dubbo_dn" dbGroup="localhost1" database="db8"/>
    <shardingNode name="solo1" dbGroup="localhost1" database="db9"/>

    <!-- 数据节点定义，数据节点由数据源和其他一些参数组织而成。 -->
    <shardingNode name="dnTest1" dbGroup="localhost4" database="db1"/>
    <shardingNode name="dnTest2" dbGroup="localhost4" database="db2"/>
    <shardingNode name="dnTest3" dbGroup="localhost4" database="db3"/>
    <!-- 路由函数定义 -->
    <function name="func0" class="com.actiontech.dble.route.function.PartitionByLong">
        <property name="partitionCount">2</property>
        <property name="partitionLength">512</property>
    </function>


    <function name="func1"
              class="com.actiontech.dble.route.function.PartitionByFileMap">
        <property name="defaultNode">0</property>
        <property name="mapFile">sharding.txt</property>
    </function>
    <function name="func"
              class="com.actiontech.dble.route.function.PartitionByString">
        <property name="partitionCount">128</property>
        <property name="partitionLength">8</property>
        <property name="hashSlice">:8</property>
    </function>
    <function name="func2" class="com.actiontech.dble.route.function.PartitionByLong">
        <property name="partitionCount">128</property>
        <property name="partitionLength">8</property>
    </function>
    <function name="rang-long"
              class="com.actiontech.dble.route.function.AutoPartitionByLong">
        <property name="mapFile">autopartition-long.txt</property>
    </function>
    <function name="rang-long2"
              class="com.actiontech.dble.route.function.AutoPartitionByLong">
        <property name="mapFile">autopartition-long2.txt</property>
    </function>
    <function name="by-date"
              class="com.actiontech.dble.route.function.PartitionByDate">
        <property name="sBeginDate">2014-01-01</property>
        <property name="sPartionDay">10</property>
        <property name="dateFormat">yyyy-MM-dd</property>
    </function>
</dble:sharding>
