|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.seatunnel.connectors.seatunnel.cdc.postgres.utils; |
| 19 | + |
| 20 | +import org.apache.seatunnel.api.table.type.BasicType; |
| 21 | +import org.apache.seatunnel.api.table.type.SeaTunnelDataType; |
| 22 | +import org.apache.seatunnel.api.table.type.SeaTunnelRowType; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Assertions; |
| 25 | +import org.junit.jupiter.api.Test; |
| 26 | + |
| 27 | +import io.debezium.relational.TableId; |
| 28 | + |
| 29 | +public class PostgresUtilsTest { |
| 30 | + @Test |
| 31 | + public void testSplitScanQuery() { |
| 32 | + String splitScanSQL = |
| 33 | + PostgresUtils.buildSplitScanQuery( |
| 34 | + TableId.parse("db1.schema1.table1"), |
| 35 | + new SeaTunnelRowType( |
| 36 | + new String[] {"id"}, new SeaTunnelDataType[] {BasicType.LONG_TYPE}), |
| 37 | + false, |
| 38 | + false); |
| 39 | + Assertions.assertEquals( |
| 40 | + "SELECT * FROM \"schema1\".\"table1\" WHERE \"id\" >= ? AND NOT (\"id\" = ?) AND \"id\" <= ?", |
| 41 | + splitScanSQL); |
| 42 | + |
| 43 | + splitScanSQL = |
| 44 | + PostgresUtils.buildSplitScanQuery( |
| 45 | + TableId.parse("db1.schema1.table1"), |
| 46 | + new SeaTunnelRowType( |
| 47 | + new String[] {"id"}, new SeaTunnelDataType[] {BasicType.LONG_TYPE}), |
| 48 | + true, |
| 49 | + true); |
| 50 | + Assertions.assertEquals("SELECT * FROM \"schema1\".\"table1\"", splitScanSQL); |
| 51 | + |
| 52 | + splitScanSQL = |
| 53 | + PostgresUtils.buildSplitScanQuery( |
| 54 | + TableId.parse("db1.schema1.table1"), |
| 55 | + new SeaTunnelRowType( |
| 56 | + new String[] {"id"}, new SeaTunnelDataType[] {BasicType.LONG_TYPE}), |
| 57 | + true, |
| 58 | + false); |
| 59 | + Assertions.assertEquals( |
| 60 | + "SELECT * FROM \"schema1\".\"table1\" WHERE \"id\" <= ? AND NOT (\"id\" = ?)", |
| 61 | + splitScanSQL); |
| 62 | + |
| 63 | + splitScanSQL = |
| 64 | + PostgresUtils.buildSplitScanQuery( |
| 65 | + TableId.parse("db1.schema1.table1"), |
| 66 | + new SeaTunnelRowType( |
| 67 | + new String[] {"id"}, new SeaTunnelDataType[] {BasicType.LONG_TYPE}), |
| 68 | + false, |
| 69 | + true); |
| 70 | + Assertions.assertEquals( |
| 71 | + "SELECT * FROM \"schema1\".\"table1\" WHERE \"id\" >= ?", splitScanSQL); |
| 72 | + } |
| 73 | +} |
0 commit comments