Implement Greedy vs Lazy matching
By default, quantifiers are greedy, meaning they match as much text as possible. To switch to lazy (non-greedy) matching, append a ? immediately after the quantifier.
Example: .* is greedy; .*? is lazy.
website·Indexed 30 days ago
https://blog.feazur.comA technical blog featuring guides and tutorials on Flink, Hadoop, Redis, Git, and Mockito, including specific configurations for DolphinScheduler, Flink on YARN, and Flink SQL support for Iceberg.
By default, quantifiers are greedy, meaning they match as much text as possible. To switch to lazy (non-greedy) matching, append a ? immediately after the quantifier.
Example: .* is greedy; .*? is lazy.
HADOOP_CLASSPATH environment variable and managing specific JAR dependencies in the Flink installation directory.# 1. Ensure HADOOP_CLASSPATH is set
# 2. Add the following JARs to FLINK_HOME/lib:
# - flink-sql-connector-hive-3.1.2.jar (or individual components:
# connector-hive_2.12-1.16.2.jar, hive-exec-3.1.0.jar,
# libfb303-0.9.3.jar, antlr-runtime-3.5.2.jar)
# 3. Move flink-table-planner_2.12-1.16.2.jar from FLINK_HOME/opt to FLINK_HOME/lib
# 4. Move flink-table-planner-loader-1.16.2.jar out of FLINK_HOME/libGrouping () allows treating multiple characters as a single unit. This is essential for applying quantifiers to strings (e.g., (good){3} matches 'goodgoodgood') and for extracting specific parts of a match.
Extraction in Java:
Matcher.group(0): Returns the entire matched string.Matcher.group(n): Returns the substring matched by the n-th group.Matcher.groupCount(): Returns the number of capturing groups in the pattern.To support Hive within Flink SQL, perform the following file system operations in the Flink installation directory:
flink-sql-connector-hive package and place it in the /lib directory.flink-table-planner package (currently in /lib) and the flink-table-planner-loader package (currently in /opt).When using Lua scripts in a Redis Cluster, you must ensure that all keys accessed by the script map to the same hash slot to avoid the error: lua script attempted to access a non local key in a cluster node.
Two critical requirements must be met:
{} in key names (e.g., {distinct}:set and {distinct}:queue). Redis only hashes the part of the key inside the braces, ensuring both keys land on the same slot.KEYS array. Scripts should not use programmatically generated key names inside the Lua logic. You can verify a key's slot using the CLUSTER KEYSLOT key command.To execute Flink SQL on a YARN session via DolphinScheduler:
flink-sql-session-application-id and set its value to the Application ID of a running YARN session.set 'execution.target' = 'yarn-session';
set 'yarn.application.id' = '${flink-sql-session-application-id}';
set 'execution.runtime-mode' = 'batch';
set 'sql-client.execution.result-mode' = 'TABLEAU';
CREATE CATALOG hive_catalog WITH (
'type' = 'hive';
'hive-conf-dir' = '/path/to/hive-conf'
);ArgumentCaptor to capture the arguments passed to a mock method during execution. This allows you to perform assertions on the captured values after the interaction has occurred.List mockList = Mockito.mock(List.class);
ArgumentCaptor<String> arg = ArgumentCaptor.forClass(String.class);
mockList.add("one");
// Capture the argument during verification
Mockito.verify(mockList).add(arg.capture());
// Retrieve and assert the captured value
assertEquals("one", arg.getValue());After enabling Hive support, add the Iceberg Flink runtime JAR to the Flink library directory. For Flink 1.16 and Iceberg 1.2.0, use iceberg-flink-runtime-1.16-1.2.0.jar.
Caveat for Huawei FusionInsight users: You may encounter NoSuchMethodError due to class dependency conflicts between the Iceberg runtime and FusionInsight. This may require recompiling the iceberg-flink-runtime JAR with updated dependencies.
# Place the following JAR in FLINK_HOME/lib
cp iceberg-flink-runtime-1.16-1.2.0.jar FLINK_HOME/lib/verify() method is used to ensure that a specific interaction occurred with a mock object. It can be used to check if a method was called, the number of times it was called, the order of calls, or if no interactions occurred at all.// Basic verification
verify(mockList).add("one");
// Verify exact number of calls
verify(mockedList, times(1)).size();
// Verify minimum/maximum calls
verify(mockedList, atLeast(1)).clear();
verify(mockedList, atMost(10)).clear();
// Verify no interactions with the mock
verifyNoInteractions(mockedList);
// Verify a specific method was never called
verify(mockedList, never()).clear();
// Verify interaction order
InOrder inOrder = Mockito.inOrder(mockedList);
inOrder.verify(mockedList).size();
inOrder.verify(mockedList).add("a parameter");
// Verify with flexible arguments
verify(mockedList).add(anyString());In Session Mode, a YARN cluster called yarn-session is created before submitting Flink jobs. Multiple jobs can be submitted to this single cluster, sharing a common JobManager and TaskManagers. The lifecycle of the yarn-session is independent of the individual jobs.
Pros:
Cons:
@InjectMocks annotation tells Mockito to create an instance of the annotated class and automatically inject any fields annotated with @Mock or @Spy into it.@Mock
Map<String, String> wordMap;
@InjectMocks
MyDictionary dic = new MyDictionary();
@Test
public void testInjection() {
Mockito.when(wordMap.get("aWord")).thenReturn("aMeaning");
assertEquals("aMeaning", dic.getMeaning("aWord"));
}// Option 1: Using JUnit 5 Extension
@ExtendWith(MockitoExtension.class)
class MyTest {}
// Option 2: Manual initialization in @BeforeEach
@BeforeEach
public void init() {
MockitoAnnotations.openMocks(this);
}