forked from apache/doris-flink-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improve] schema change idempotent with add and drop column (apache#250)
- Loading branch information
Showing
6 changed files
with
225 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...-connector/src/main/java/org/apache/doris/flink/exception/DorisSchemaChangeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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. | ||
|
||
package org.apache.doris.flink.exception; | ||
|
||
/** | ||
* Doris Schema Change run exception. | ||
*/ | ||
public class DorisSchemaChangeException extends RuntimeException { | ||
public DorisSchemaChangeException() { | ||
super(); | ||
} | ||
|
||
public DorisSchemaChangeException(String message) { | ||
super(message); | ||
} | ||
|
||
public DorisSchemaChangeException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public DorisSchemaChangeException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
protected DorisSchemaChangeException(String message, Throwable cause, | ||
boolean enableSuppression, | ||
boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...k-doris-connector/src/test/java/org/apache/doris/flink/sink/schema/SchemaManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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. | ||
|
||
package org.apache.doris.flink.sink.schema; | ||
|
||
import org.apache.doris.flink.cfg.DorisOptions; | ||
import org.apache.doris.flink.exception.IllegalArgumentException; | ||
import org.apache.doris.flink.sink.HttpEntityMock; | ||
import org.apache.doris.flink.sink.OptionUtils; | ||
import org.apache.http.ProtocolVersion; | ||
import org.apache.http.StatusLine; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.message.BasicStatusLine; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.MockedStatic; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class SchemaManagerTest { | ||
|
||
static String QUERY_RESPONSE = "{\n" + | ||
" \"data\": {\n" + | ||
" \"type\": \"result_set\",\n" + | ||
" \"meta\": [{\"name\":\"COLUMN_NAME\",\"type\":\"CHAR\"}],\n" + | ||
" \"data\": [\n" + | ||
" [\"age\"]\n" + | ||
" ],\n" + | ||
" \"time\": 15\n" + | ||
" },\n" + | ||
" \"msg\": \"success\",\n" + | ||
" \"code\": 0\n" + | ||
"}"; | ||
|
||
static String QUERY_NO_EXISTS_RESPONSE = "{\n" + | ||
" \"data\": {\n" + | ||
" \"type\": \"result_set\",\n" + | ||
" \"meta\": [{\"name\":\"COLUMN_NAME\",\"type\":\"CHAR\"}],\n" + | ||
" \"data\": [],\n" + | ||
" \"time\": 0\n" + | ||
" },\n" + | ||
" \"msg\": \"success\",\n" + | ||
" \"code\": 0\n" + | ||
"}"; | ||
|
||
HttpEntityMock entityMock; | ||
SchemaChangeManager schemaChangeManager; | ||
static MockedStatic<HttpClients> httpClientMockedStatic = mockStatic(HttpClients.class); | ||
|
||
|
||
@Before | ||
public void setUp() throws IOException { | ||
DorisOptions dorisOptions = OptionUtils.buildDorisOptions(); | ||
schemaChangeManager = new SchemaChangeManager(dorisOptions); | ||
CloseableHttpClient httpClient = mock(CloseableHttpClient.class); | ||
entityMock = new HttpEntityMock(); | ||
|
||
CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class); | ||
StatusLine normalLine = new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, ""); | ||
|
||
when(httpClient.execute(any())).thenReturn(httpResponse); | ||
when(httpResponse.getStatusLine()).thenReturn(normalLine); | ||
when(httpResponse.getEntity()).thenReturn(entityMock); | ||
when(httpClient.execute(any())).thenReturn(httpResponse); | ||
when(httpResponse.getStatusLine()).thenReturn(normalLine); | ||
when(httpResponse.getEntity()).thenReturn(entityMock); | ||
|
||
httpClientMockedStatic.when(()-> HttpClients.createDefault()) | ||
.thenReturn(httpClient); | ||
} | ||
|
||
@Test | ||
public void testColumnExists() throws IOException, IllegalArgumentException { | ||
entityMock.setValue(QUERY_RESPONSE); | ||
boolean columnExists = schemaChangeManager.checkColumnExists("test", "test_flink", "age"); | ||
System.out.println(columnExists); | ||
} | ||
|
||
@Test | ||
public void testColumnNotExists() throws IOException, IllegalArgumentException { | ||
entityMock.setValue(QUERY_NO_EXISTS_RESPONSE); | ||
boolean columnExists = schemaChangeManager.checkColumnExists("test", "test_flink", "age1"); | ||
System.out.println(columnExists); | ||
} | ||
|
||
} |