Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String identifier() {

@Override
public Optional<Action> create(MultipleParameterToolAdapter params) {
Long timestamp = Long.parseLong(params.get(TIMESTAMP));
Long timestamp = Long.parseLong(params.getRequired(TIMESTAMP));
String timeRetained = params.get(TIME_RETAINED);
Map<String, String> catalogConfig = catalogConfigMap(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public String identifier() {

@Override
public Optional<Action> create(MultipleParameterToolAdapter params) {
String tag = params.get(TAG);
Long watermark = Long.parseLong(params.get(WATERMARK));
String tag = params.getRequired(TAG);
Long watermark = Long.parseLong(params.getRequired(WATERMARK));
String timeRetained = params.get(TIME_RETAINED);
Map<String, String> catalogConfig = catalogConfigMap(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Optional<Action> create(MultipleParameterToolAdapter params) {
action.withMergeCondition(params.getRequired(ON));

List<String> actions =
Arrays.stream(params.get(MERGE_ACTIONS).split(","))
Arrays.stream(params.getRequired(MERGE_ACTIONS).split(","))
.map(String::trim)
.collect(Collectors.toList());
if (actions.contains(MATCHED_UPSERT)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.paimon.flink.action;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/** Tests for {@link CreateTagFromTimestampActionFactory#create}. */
public class CreateTagFromTimestampActionFactoryTest extends ActionITCaseBase {

@Test
public void testMissingTimestampReportsRequiredArgument() {
assertThatThrownBy(
() ->
createAction(
CreateTagFromTimestampAction.class,
"create_tag_from_timestamp",
"--warehouse",
warehouse,
"--database",
database,
"--table",
tableName,
"--tag",
"tag_1"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Argument 'timestamp' is required");
}

@Test
public void testCreateWithTimestamp() {
assertThatCode(
() ->
assertThat(
createAction(
CreateTagFromTimestampAction.class,
"create_tag_from_timestamp",
"--warehouse",
warehouse,
"--database",
database,
"--table",
tableName,
"--tag",
"tag_1",
"--timestamp",
"1000"))
.isNotNull())
.doesNotThrowAnyException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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.paimon.flink.action;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/** Tests for {@link CreateTagFromWatermarkActionFactory#create}. */
public class CreateTagFromWatermarkActionFactoryTest extends ActionITCaseBase {

@Test
public void testMissingWatermarkReportsRequiredArgument() {
assertThatThrownBy(
() ->
createAction(
CreateTagFromWatermarkAction.class,
"create_tag_from_watermark",
"--warehouse",
warehouse,
"--database",
database,
"--table",
tableName,
"--tag",
"tag_1"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Argument 'watermark' is required");
}

@Test
public void testMissingTagReportsRequiredArgument() {
assertThatThrownBy(
() ->
createAction(
CreateTagFromWatermarkAction.class,
"create_tag_from_watermark",
"--warehouse",
warehouse,
"--database",
database,
"--table",
tableName,
"--watermark",
"1000"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Argument 'tag' is required");
}

@Test
public void testCreateWithTagAndWatermark() {
assertThatCode(
() ->
assertThat(
createAction(
CreateTagFromWatermarkAction.class,
"create_tag_from_watermark",
"--warehouse",
warehouse,
"--database",
database,
"--table",
tableName,
"--tag",
"tag_1",
"--watermark",
"1000"))
.isNotNull())
.doesNotThrowAnyException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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.paimon.flink.action;

import org.apache.paimon.types.DataType;
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.types.RowType;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.HashMap;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/** Tests for {@link MergeIntoActionFactory#create}. */
public class MergeIntoActionFactoryTest extends ActionITCaseBase {

@BeforeEach
public void setUp() throws Exception {
// merge_into loads the target table before parsing --merge_actions, so it must exist and
// must have primary keys
DataType[] fieldTypes = new DataType[] {DataTypes.INT(), DataTypes.STRING()};
RowType rowType = RowType.of(fieldTypes, new String[] {"k", "v"});
createFileStoreTable(
rowType,
Collections.emptyList(),
Collections.singletonList("k"),
Collections.emptyList(),
new HashMap<>());
}

@Test
public void testMissingMergeActionsReportsRequiredArgument() {
assertThatThrownBy(
() ->
createAction(
MergeIntoAction.class,
"merge_into",
"--warehouse",
warehouse,
"--database",
database,
"--table",
tableName,
"--source_table",
"S",
"--on",
"T.k = S.k"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Argument 'merge_actions' is required");
}

@Test
public void testCreateWithMergeActions() {
assertThatCode(
() ->
assertThat(
createAction(
MergeIntoAction.class,
"merge_into",
"--warehouse",
warehouse,
"--database",
database,
"--table",
tableName,
"--source_table",
"S",
"--on",
"T.k = S.k",
"--merge_actions",
"matched-upsert",
"--matched_upsert_set",
"v = S.v"))
.isNotNull())
.doesNotThrowAnyException();
}
}
Loading