target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void testEqualsReturnsTrueWithBooleanFalseFalse() { assertTrue(KeyUtils.equals(Boolean.FALSE, Boolean.FALSE)); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseWithBooleanTrueFalse() { assertFalse(KeyUtils.equals(Boolean.TRUE, Boolean.FALSE)); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseWithBooleanFalseTrue() { assertFalse(KeyUtils.equals(Boolean.FALSE, Boolean.TRUE)); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void runWithOptions() throws Exception { getCurrentDremioDaemon().close(); Clean.go(new String[] {}); Clean.go(new String[] {"-o", "-i", "-c", "-j=30", "-p"}); Clean.go(new String[] {"-h"}); } | public static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); final Options options = Options.parse(args); if(options.help) { return; } if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Cleanup should be run on master node"); } Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); if (provider.getStores().size() == 0) { AdminLogger.log("No store stats available"); } if(options.hasActiveOperation()) { AdminLogger.log("Initial Store Status."); } else { AdminLogger.log("No operation requested. "); } for(StoreWithId<?, ?> id : provider) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } if(options.deleteOrphans) { deleteSplitOrphans(provider.asLegacy()); deleteCollaborationOrphans(provider.asLegacy()); } if(options.maxJobDays < Integer.MAX_VALUE) { deleteOldJobsAndProfiles(provider.asLegacy(), options.maxJobDays); } if (options.deleteOrphanProfiles) { deleteOrphanProfiles(provider.asLegacy()); } if(options.reindexData) { reindexData(provider); } if(options.compactKvStore) { compactStore(provider); } if(options.hasActiveOperation()) { AdminLogger.log("\n\nFinal Store Status."); for(StoreWithId<?, ?> id : provider.unwrap(LocalKVStoreProvider.class)) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } } return; } } | Clean { public static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); final Options options = Options.parse(args); if(options.help) { return; } if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Cleanup should be run on master node"); } Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); if (provider.getStores().size() == 0) { AdminLogger.log("No store stats available"); } if(options.hasActiveOperation()) { AdminLogger.log("Initial Store Status."); } else { AdminLogger.log("No operation requested. "); } for(StoreWithId<?, ?> id : provider) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } if(options.deleteOrphans) { deleteSplitOrphans(provider.asLegacy()); deleteCollaborationOrphans(provider.asLegacy()); } if(options.maxJobDays < Integer.MAX_VALUE) { deleteOldJobsAndProfiles(provider.asLegacy(), options.maxJobDays); } if (options.deleteOrphanProfiles) { deleteOrphanProfiles(provider.asLegacy()); } if(options.reindexData) { reindexData(provider); } if(options.compactKvStore) { compactStore(provider); } if(options.hasActiveOperation()) { AdminLogger.log("\n\nFinal Store Status."); for(StoreWithId<?, ?> id : provider.unwrap(LocalKVStoreProvider.class)) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } } return; } } } | Clean { public static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); final Options options = Options.parse(args); if(options.help) { return; } if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Cleanup should be run on master node"); } Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); if (provider.getStores().size() == 0) { AdminLogger.log("No store stats available"); } if(options.hasActiveOperation()) { AdminLogger.log("Initial Store Status."); } else { AdminLogger.log("No operation requested. "); } for(StoreWithId<?, ?> id : provider) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } if(options.deleteOrphans) { deleteSplitOrphans(provider.asLegacy()); deleteCollaborationOrphans(provider.asLegacy()); } if(options.maxJobDays < Integer.MAX_VALUE) { deleteOldJobsAndProfiles(provider.asLegacy(), options.maxJobDays); } if (options.deleteOrphanProfiles) { deleteOrphanProfiles(provider.asLegacy()); } if(options.reindexData) { reindexData(provider); } if(options.compactKvStore) { compactStore(provider); } if(options.hasActiveOperation()) { AdminLogger.log("\n\nFinal Store Status."); for(StoreWithId<?, ?> id : provider.unwrap(LocalKVStoreProvider.class)) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } } return; } } } | Clean { public static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); final Options options = Options.parse(args); if(options.help) { return; } if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Cleanup should be run on master node"); } Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); if (provider.getStores().size() == 0) { AdminLogger.log("No store stats available"); } if(options.hasActiveOperation()) { AdminLogger.log("Initial Store Status."); } else { AdminLogger.log("No operation requested. "); } for(StoreWithId<?, ?> id : provider) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } if(options.deleteOrphans) { deleteSplitOrphans(provider.asLegacy()); deleteCollaborationOrphans(provider.asLegacy()); } if(options.maxJobDays < Integer.MAX_VALUE) { deleteOldJobsAndProfiles(provider.asLegacy(), options.maxJobDays); } if (options.deleteOrphanProfiles) { deleteOrphanProfiles(provider.asLegacy()); } if(options.reindexData) { reindexData(provider); } if(options.compactKvStore) { compactStore(provider); } if(options.hasActiveOperation()) { AdminLogger.log("\n\nFinal Store Status."); for(StoreWithId<?, ?> id : provider.unwrap(LocalKVStoreProvider.class)) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } } return; } } static void go(String[] args); static void main(String[] args); } | Clean { public static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); final Options options = Options.parse(args); if(options.help) { return; } if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Cleanup should be run on master node"); } Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); if (provider.getStores().size() == 0) { AdminLogger.log("No store stats available"); } if(options.hasActiveOperation()) { AdminLogger.log("Initial Store Status."); } else { AdminLogger.log("No operation requested. "); } for(StoreWithId<?, ?> id : provider) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } if(options.deleteOrphans) { deleteSplitOrphans(provider.asLegacy()); deleteCollaborationOrphans(provider.asLegacy()); } if(options.maxJobDays < Integer.MAX_VALUE) { deleteOldJobsAndProfiles(provider.asLegacy(), options.maxJobDays); } if (options.deleteOrphanProfiles) { deleteOrphanProfiles(provider.asLegacy()); } if(options.reindexData) { reindexData(provider); } if(options.compactKvStore) { compactStore(provider); } if(options.hasActiveOperation()) { AdminLogger.log("\n\nFinal Store Status."); for(StoreWithId<?, ?> id : provider.unwrap(LocalKVStoreProvider.class)) { KVAdmin admin = id.getStore().getAdmin(); AdminLogger.log(admin.getStats()); } } return; } } static void go(String[] args); static void main(String[] args); } |
@Test public void testEqualsReturnsTrueWithByteArrays() { byte[] left = new byte[]{0, 1, 2, 3, 4}; byte[] right = new byte[]{0, 1, 2, 3, 4}; assertTrue(KeyUtils.equals(left, right)); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseWithByteArrays() { byte[] left = new byte[]{0, 1, 2, 3, 4}; byte[] right = new byte[]{0, 1, 2, 3, 5}; assertFalse(KeyUtils.equals(left, right)); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseWithByteArraysDifferentLength() { byte[] left = new byte[]{0, 1, 2, 3, 4}; byte[] right = new byte[]{0, 1, 2, 3}; assertFalse(KeyUtils.equals(left, right)); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsTrueByteProtoObject() { assertTrue(KeyUtils.equals( new KeyPair<>( TEST_STRING.getBytes(UTF_8), "some other silly string".getBytes(UTF_8)), new KeyPair<>( TEST_STRING.getBytes(UTF_8), "some other silly string".getBytes(UTF_8)))); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseByteProtoObject() { assertFalse(KeyUtils.equals( new KeyPair<>( TEST_STRING.getBytes(UTF_8), "some other silly string".getBytes(UTF_8)), new KeyPair<>( TEST_STRING.getBytes(UTF_8), "some other silly".getBytes(UTF_8)))); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseByteProtoObjectWithNull() { assertFalse(KeyUtils.equals( new KeyPair<>( TEST_STRING.getBytes(UTF_8), "some other silly string".getBytes(UTF_8)), new KeyPair<>( TEST_STRING.getBytes(UTF_8), null))); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseWithProtoObjectsDifferentUUID() { assertFalse(KeyUtils.equals( new KeyPair<>( PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID()), new KeyTriple<>( "Some string", PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID()))); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testEqualsReturnsFalseWithNestedProtoObjectsDifferentUUID() { assertFalse(KeyUtils.equals( new KeyTriple<>( new KeyPair<>(PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID()), new KeyTriple<>("Some string", PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID()), new KeyTriple<>("Some string", PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID())), new KeyTriple<>( new KeyPair<>(PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID()), new KeyTriple<>("Some string", PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID()), new KeyTriple<>("Some string", PROTOBUFF_ORIGINAL_STRING, UUID.randomUUID())))); } | public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static boolean equals(Object left, Object right) { if (left instanceof byte[] && right instanceof byte[]) { return Arrays.equals((byte[]) left, (byte[]) right); } return Objects.equals(left, right); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testToStringNull() { assertNull(KeyUtils.toString(null)); } | public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testToStringBytes() { assertEquals("[1, 2, 3, 4]", KeyUtils.toString(new byte[]{1, 2, 3, 4})); } | public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void runCommand() throws Exception { assertFalse(TestCommand.invokedCorrectly); AdminCommandRunner.runCommand("test-command", TestCommand.class, new String[]{"arg0", "arg1"}); assertTrue(TestCommand.invokedCorrectly); } | static void runCommand(String commandName, Class<?> command, String[] commandArgs) throws Exception { final Method mainMethod = command.getMethod("main", String[].class); Preconditions.checkState(Modifier.isStatic(mainMethod.getModifiers()) && Modifier.isPublic(mainMethod.getModifiers()), "#main(String[]) must have public and static modifiers"); final Object[] objects = new Object[1]; objects[0] = commandArgs; try { mainMethod.invoke(null, objects); } catch (final ReflectiveOperationException e) { final Throwable cause = e.getCause() != null ? e.getCause() : e; Throwables.throwIfUnchecked(cause); throw new RuntimeException(String.format("Failed to run '%s' command", commandName), e); } } | AdminCommandRunner { static void runCommand(String commandName, Class<?> command, String[] commandArgs) throws Exception { final Method mainMethod = command.getMethod("main", String[].class); Preconditions.checkState(Modifier.isStatic(mainMethod.getModifiers()) && Modifier.isPublic(mainMethod.getModifiers()), "#main(String[]) must have public and static modifiers"); final Object[] objects = new Object[1]; objects[0] = commandArgs; try { mainMethod.invoke(null, objects); } catch (final ReflectiveOperationException e) { final Throwable cause = e.getCause() != null ? e.getCause() : e; Throwables.throwIfUnchecked(cause); throw new RuntimeException(String.format("Failed to run '%s' command", commandName), e); } } } | AdminCommandRunner { static void runCommand(String commandName, Class<?> command, String[] commandArgs) throws Exception { final Method mainMethod = command.getMethod("main", String[].class); Preconditions.checkState(Modifier.isStatic(mainMethod.getModifiers()) && Modifier.isPublic(mainMethod.getModifiers()), "#main(String[]) must have public and static modifiers"); final Object[] objects = new Object[1]; objects[0] = commandArgs; try { mainMethod.invoke(null, objects); } catch (final ReflectiveOperationException e) { final Throwable cause = e.getCause() != null ? e.getCause() : e; Throwables.throwIfUnchecked(cause); throw new RuntimeException(String.format("Failed to run '%s' command", commandName), e); } } } | AdminCommandRunner { static void runCommand(String commandName, Class<?> command, String[] commandArgs) throws Exception { final Method mainMethod = command.getMethod("main", String[].class); Preconditions.checkState(Modifier.isStatic(mainMethod.getModifiers()) && Modifier.isPublic(mainMethod.getModifiers()), "#main(String[]) must have public and static modifiers"); final Object[] objects = new Object[1]; objects[0] = commandArgs; try { mainMethod.invoke(null, objects); } catch (final ReflectiveOperationException e) { final Throwable cause = e.getCause() != null ? e.getCause() : e; Throwables.throwIfUnchecked(cause); throw new RuntimeException(String.format("Failed to run '%s' command", commandName), e); } } static void main(String[] args); } | AdminCommandRunner { static void runCommand(String commandName, Class<?> command, String[] commandArgs) throws Exception { final Method mainMethod = command.getMethod("main", String[].class); Preconditions.checkState(Modifier.isStatic(mainMethod.getModifiers()) && Modifier.isPublic(mainMethod.getModifiers()), "#main(String[]) must have public and static modifiers"); final Object[] objects = new Object[1]; objects[0] = commandArgs; try { mainMethod.invoke(null, objects); } catch (final ReflectiveOperationException e) { final Throwable cause = e.getCause() != null ? e.getCause() : e; Throwables.throwIfUnchecked(cause); throw new RuntimeException(String.format("Failed to run '%s' command", commandName), e); } } static void main(String[] args); } |
@Test public void testToStringString() { assertEquals("[1, 2, 3, 4]", KeyUtils.toString("[1, 2, 3, 4]")); } | public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testToStringProtoStringBytesKeyPair() { assertEquals("KeyPair{ key1=somestring, key2=[1, 23, 43, 5]}", KeyUtils.toString( new KeyPair<>("somestring", new byte[]{1, 23, 43, 5}))); } | public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testToStringProtoByteKeyPairByteKeyTriple() { assertEquals("KeyTriple{ key1=[123, 127, 9, 0], key2=KeyPair{ key1=somestring, key2=[1, 23, 43, 5]}, key3=[0, 0, 0, 0]}", KeyUtils.toString( new KeyTriple<>( new byte[]{123, 127, 9, 0}, new KeyPair<>("somestring", new byte[]{1, 23, 43, 5}), new byte[]{0, 0, 0, 0}))); } | public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static String toString(Object key) { if (null == key) { return null; } return (key instanceof byte[] ? Arrays.toString((byte[]) key) : key.toString()); } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testHashBytes() { assertEquals(918073283, KeyUtils.hash(new byte[]{1, 2, 3, 4, 5, 6})); } | public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testHashBytesAndString() { assertEquals(214780274, KeyUtils.hash(new byte[]{1, 2, 3, 4, 5, 6}, "test hash string")); } | public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testHashBytesAndStringAndNull() { assertEquals(-1931746098, KeyUtils.hash(new byte[]{1, 2, 3, 4, 5, 6}, "test hash string", null)); } | public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testHashString() { assertEquals(1819279604, KeyUtils.hash("test hash string")); } | public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testHashNull() { assertEquals(0, KeyUtils.hash(null)); } | public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } | KeyUtils { public static int hash(Object... keys) { if (null == keys) { return 0; } int result = 1; for (Object key : keys) { result = 31 * result + hashCode(key); } return result; } private KeyUtils(); static boolean equals(Object left, Object right); static int hash(Object... keys); static String toString(Object key); } |
@Test public void testOf() { if (!valid) { thrown.expect(IllegalArgumentException.class); } final KeyTriple<String, String, String> keyPair = KeyTriple.of(values); assertNotNull(keyPair); assertEquals(values.get(0), keyPair.getKey1()); assertEquals(values.get(1), keyPair.getKey2()); assertEquals(values.get(2), keyPair.getKey3()); assertEquals(values, keyPair); } | @SuppressWarnings("unchecked") public static <K1, K2, K3> KeyTriple<K1, K2, K3> of(List<Object> list) { checkArgument(list.size() == 3, "list should be of size 3, had actually %s elements", list); final K1 value1 = (K1) list.get(0); final K2 value2 = (K2) list.get(1); final K3 value3 = (K3) list.get(2); return new KeyTriple<>(value1, value2, value3); } | KeyTriple extends AbstractList<Object> implements CompoundKey { @SuppressWarnings("unchecked") public static <K1, K2, K3> KeyTriple<K1, K2, K3> of(List<Object> list) { checkArgument(list.size() == 3, "list should be of size 3, had actually %s elements", list); final K1 value1 = (K1) list.get(0); final K2 value2 = (K2) list.get(1); final K3 value3 = (K3) list.get(2); return new KeyTriple<>(value1, value2, value3); } } | KeyTriple extends AbstractList<Object> implements CompoundKey { @SuppressWarnings("unchecked") public static <K1, K2, K3> KeyTriple<K1, K2, K3> of(List<Object> list) { checkArgument(list.size() == 3, "list should be of size 3, had actually %s elements", list); final K1 value1 = (K1) list.get(0); final K2 value2 = (K2) list.get(1); final K3 value3 = (K3) list.get(2); return new KeyTriple<>(value1, value2, value3); } KeyTriple(K1 key1, K2 key2, K3 key3); } | KeyTriple extends AbstractList<Object> implements CompoundKey { @SuppressWarnings("unchecked") public static <K1, K2, K3> KeyTriple<K1, K2, K3> of(List<Object> list) { checkArgument(list.size() == 3, "list should be of size 3, had actually %s elements", list); final K1 value1 = (K1) list.get(0); final K2 value2 = (K2) list.get(1); final K3 value3 = (K3) list.get(2); return new KeyTriple<>(value1, value2, value3); } KeyTriple(K1 key1, K2 key2, K3 key3); @SuppressWarnings("unchecked") static KeyTriple<K1, K2, K3> of(List<Object> list); @Override Object get(int index); @Override int size(); K1 getKey1(); K2 getKey2(); K3 getKey3(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); } | KeyTriple extends AbstractList<Object> implements CompoundKey { @SuppressWarnings("unchecked") public static <K1, K2, K3> KeyTriple<K1, K2, K3> of(List<Object> list) { checkArgument(list.size() == 3, "list should be of size 3, had actually %s elements", list); final K1 value1 = (K1) list.get(0); final K2 value2 = (K2) list.get(1); final K3 value3 = (K3) list.get(2); return new KeyTriple<>(value1, value2, value3); } KeyTriple(K1 key1, K2 key2, K3 key3); @SuppressWarnings("unchecked") static KeyTriple<K1, K2, K3> of(List<Object> list); @Override Object get(int index); @Override int size(); K1 getKey1(); K2 getKey2(); K3 getKey3(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); } |
@Test public void add() throws Exception { LuceneSearchIndex index = mock(LuceneSearchIndex.class); final boolean[] added = {false}; doAnswer(invocation -> { added[0] = true; return null; }).when(index).update(any(Term.class), any(Document.class)); when(indexManager.getIndex(same(storeName))) .thenReturn(index); reIndexer.put(storeName, one, two); assertTrue(added[0]); } | @Override public void put(String tableName, byte[] key, byte[] value) { if (!isIndexed(tableName)) { logger.trace("Ignoring put: {} on table '{}'", key, tableName); return; } final KVStoreTuple<?> keyTuple = keyTuple(tableName, key); final Document document = toDoc(tableName, keyTuple, valueTuple(tableName, value)); if (document != null) { indexManager.getIndex(tableName) .update(keyAsTerm(keyTuple), document); metrics(tableName).puts++; } } | ReIndexer implements ReplayHandler { @Override public void put(String tableName, byte[] key, byte[] value) { if (!isIndexed(tableName)) { logger.trace("Ignoring put: {} on table '{}'", key, tableName); return; } final KVStoreTuple<?> keyTuple = keyTuple(tableName, key); final Document document = toDoc(tableName, keyTuple, valueTuple(tableName, value)); if (document != null) { indexManager.getIndex(tableName) .update(keyAsTerm(keyTuple), document); metrics(tableName).puts++; } } } | ReIndexer implements ReplayHandler { @Override public void put(String tableName, byte[] key, byte[] value) { if (!isIndexed(tableName)) { logger.trace("Ignoring put: {} on table '{}'", key, tableName); return; } final KVStoreTuple<?> keyTuple = keyTuple(tableName, key); final Document document = toDoc(tableName, keyTuple, valueTuple(tableName, value)); if (document != null) { indexManager.getIndex(tableName) .update(keyAsTerm(keyTuple), document); metrics(tableName).puts++; } } ReIndexer(IndexManager indexManager, Map<String, StoreWithId<?, ?>> idToStore); } | ReIndexer implements ReplayHandler { @Override public void put(String tableName, byte[] key, byte[] value) { if (!isIndexed(tableName)) { logger.trace("Ignoring put: {} on table '{}'", key, tableName); return; } final KVStoreTuple<?> keyTuple = keyTuple(tableName, key); final Document document = toDoc(tableName, keyTuple, valueTuple(tableName, value)); if (document != null) { indexManager.getIndex(tableName) .update(keyAsTerm(keyTuple), document); metrics(tableName).puts++; } } ReIndexer(IndexManager indexManager, Map<String, StoreWithId<?, ?>> idToStore); @Override void put(String tableName, byte[] key, byte[] value); @Override void delete(String tableName, byte[] key); } | ReIndexer implements ReplayHandler { @Override public void put(String tableName, byte[] key, byte[] value) { if (!isIndexed(tableName)) { logger.trace("Ignoring put: {} on table '{}'", key, tableName); return; } final KVStoreTuple<?> keyTuple = keyTuple(tableName, key); final Document document = toDoc(tableName, keyTuple, valueTuple(tableName, value)); if (document != null) { indexManager.getIndex(tableName) .update(keyAsTerm(keyTuple), document); metrics(tableName).puts++; } } ReIndexer(IndexManager indexManager, Map<String, StoreWithId<?, ?>> idToStore); @Override void put(String tableName, byte[] key, byte[] value); @Override void delete(String tableName, byte[] key); } |
@Test public void testOffline() throws Exception { final String tmpPath = folder0.newFolder("testOffline").getAbsolutePath(); final LegacyKVStoreProvider localKVStoreProvider = l(LegacyKVStoreProvider.class); final LegacyKVStoreProvider spy = spy(localKVStoreProvider); Mockito.doNothing().when(spy).close(); final String[] args = {"-o", "--output", tmpPath, "--format", "JSON", "--write-mode", "FAIL_IF_EXISTS"}; final ExportProfiles.ExportProfilesOptions options = getExportOptions(args); ExportProfiles.exportOffline(options, spy); verifyResult(tmpPath, queryProfile, String.join(" ", args)); } | private static void exportOffline(ExportProfilesOptions options, DACConfig dacConfig) throws Exception { Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No database found. Profiles are not exported"); return; } try (LocalKVStoreProvider kvStoreProvider = providerOptional.get()) { kvStoreProvider.start(); exportOffline(options, kvStoreProvider.asLegacy()); } } | ExportProfiles { private static void exportOffline(ExportProfilesOptions options, DACConfig dacConfig) throws Exception { Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No database found. Profiles are not exported"); return; } try (LocalKVStoreProvider kvStoreProvider = providerOptional.get()) { kvStoreProvider.start(); exportOffline(options, kvStoreProvider.asLegacy()); } } } | ExportProfiles { private static void exportOffline(ExportProfilesOptions options, DACConfig dacConfig) throws Exception { Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No database found. Profiles are not exported"); return; } try (LocalKVStoreProvider kvStoreProvider = providerOptional.get()) { kvStoreProvider.start(); exportOffline(options, kvStoreProvider.asLegacy()); } } } | ExportProfiles { private static void exportOffline(ExportProfilesOptions options, DACConfig dacConfig) throws Exception { Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No database found. Profiles are not exported"); return; } try (LocalKVStoreProvider kvStoreProvider = providerOptional.get()) { kvStoreProvider.start(); exportOffline(options, kvStoreProvider.asLegacy()); } } static void main(String[] args); } | ExportProfiles { private static void exportOffline(ExportProfilesOptions options, DACConfig dacConfig) throws Exception { Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("No database found. Profiles are not exported"); return; } try (LocalKVStoreProvider kvStoreProvider = providerOptional.get()) { kvStoreProvider.start(); exportOffline(options, kvStoreProvider.asLegacy()); } } static void main(String[] args); } |
@Test public void testTasksOrder() { DACConfig dacConfig = DACConfig.newConfig(); Upgrade upgrade = new Upgrade(dacConfig, CLASSPATH_SCAN_RESULT, false); List<? extends UpgradeTask> tasks = upgrade.getUpgradeTasks(); boolean isMapr = Boolean.valueOf(System.getProperty("dremio.mapr.profile")); boolean containsS3Task = false; int s3TaskIndex = 0; boolean containsDatasetSplitTask = false; int datasetSplitTaskIndex = 0; for (int i = 0; i < tasks.size(); i++) { String taskName = tasks.get(i).getClass().getName(); if ("com.dremio.dac.cmd.upgrade.UpdateS3CredentialType".equals(taskName)) { containsS3Task = true; s3TaskIndex = i; } else if ("com.dremio.dac.cmd.upgrade.UpdateDatasetSplitIdTask".equals(taskName)) { containsDatasetSplitTask = true; datasetSplitTaskIndex = i; } } if (isMapr) { assertFalse(containsS3Task); } else { assertTrue(containsDatasetSplitTask); assertTrue(containsS3Task); assertTrue(s3TaskIndex > datasetSplitTaskIndex); tasks.remove(s3TaskIndex); } assertThat(tasks, contains( instanceOf(DatasetConfigUpgrade.class), instanceOf(ReIndexAllStores.class), instanceOf(UpdateDatasetSplitIdTask.class), instanceOf(DeleteHistoryOfRenamedDatasets.class), instanceOf(DeleteHive121BasedInputSplits.class), instanceOf(MinimizeJobResultsMetadata.class), instanceOf(UpdateExternalReflectionHash.class), instanceOf(DeleteSysMaterializationsMetadata.class), instanceOf(SetTableauDefaults.class), instanceOf(TopPriorityTask.class), instanceOf(LowPriorityTask.class) )); } | @VisibleForTesting List<? extends UpgradeTask> getUpgradeTasks() { return upgradeTasks; } | Upgrade { @VisibleForTesting List<? extends UpgradeTask> getUpgradeTasks() { return upgradeTasks; } } | Upgrade { @VisibleForTesting List<? extends UpgradeTask> getUpgradeTasks() { return upgradeTasks; } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); } | Upgrade { @VisibleForTesting List<? extends UpgradeTask> getUpgradeTasks() { return upgradeTasks; } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); void run(); void run(boolean noDBOpenRetry); @VisibleForTesting void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition); void run(final LegacyKVStoreProvider storeProvider); static void main(String[] args); } | Upgrade { @VisibleForTesting List<? extends UpgradeTask> getUpgradeTasks() { return upgradeTasks; } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); void run(); void run(boolean noDBOpenRetry); @VisibleForTesting void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition); void run(final LegacyKVStoreProvider storeProvider); static void main(String[] args); static final Comparator<Version> UPGRADE_VERSION_ORDERING; } |
@Test public void delete() throws Exception { LuceneSearchIndex index = mock(LuceneSearchIndex.class); final boolean[] deleted = {false}; doAnswer(invocation -> { deleted[0] = true; return null; }).when(index).deleteDocuments(any(Term.class)); when(indexManager.getIndex(same(storeName))) .thenReturn(index); reIndexer.delete(storeName, one); assertTrue(deleted[0]); } | @Override public void delete(String tableName, byte[] key) { if (!isIndexed(tableName)) { logger.trace("Ignoring delete: {} on table '{}'", key, tableName); return; } indexManager.getIndex(tableName) .deleteDocuments(keyAsTerm(keyTuple(tableName, key))); metrics(tableName).deletes++; } | ReIndexer implements ReplayHandler { @Override public void delete(String tableName, byte[] key) { if (!isIndexed(tableName)) { logger.trace("Ignoring delete: {} on table '{}'", key, tableName); return; } indexManager.getIndex(tableName) .deleteDocuments(keyAsTerm(keyTuple(tableName, key))); metrics(tableName).deletes++; } } | ReIndexer implements ReplayHandler { @Override public void delete(String tableName, byte[] key) { if (!isIndexed(tableName)) { logger.trace("Ignoring delete: {} on table '{}'", key, tableName); return; } indexManager.getIndex(tableName) .deleteDocuments(keyAsTerm(keyTuple(tableName, key))); metrics(tableName).deletes++; } ReIndexer(IndexManager indexManager, Map<String, StoreWithId<?, ?>> idToStore); } | ReIndexer implements ReplayHandler { @Override public void delete(String tableName, byte[] key) { if (!isIndexed(tableName)) { logger.trace("Ignoring delete: {} on table '{}'", key, tableName); return; } indexManager.getIndex(tableName) .deleteDocuments(keyAsTerm(keyTuple(tableName, key))); metrics(tableName).deletes++; } ReIndexer(IndexManager indexManager, Map<String, StoreWithId<?, ?>> idToStore); @Override void put(String tableName, byte[] key, byte[] value); @Override void delete(String tableName, byte[] key); } | ReIndexer implements ReplayHandler { @Override public void delete(String tableName, byte[] key) { if (!isIndexed(tableName)) { logger.trace("Ignoring delete: {} on table '{}'", key, tableName); return; } indexManager.getIndex(tableName) .deleteDocuments(keyAsTerm(keyTuple(tableName, key))); metrics(tableName).deletes++; } ReIndexer(IndexManager indexManager, Map<String, StoreWithId<?, ?>> idToStore); @Override void put(String tableName, byte[] key, byte[] value); @Override void delete(String tableName, byte[] key); } |
@Test public void testTypedReturnMethod() { setupLegitParentSpan(); when(delegate.get("myKey")).thenReturn(new TestDocument("myKey","yourValue")); Document<String, String> ret = underTest.get("myKey"); assertEquals("yourValue", ret.getValue()); assertChildSpanMethod("get"); } | @Override public Document<K, V> get(K key, GetOption... options) { return trace("get", () -> delegate.get(key, options)); } | TracingKVStore implements KVStore<K, V> { @Override public Document<K, V> get(K key, GetOption... options) { return trace("get", () -> delegate.get(key, options)); } } | TracingKVStore implements KVStore<K, V> { @Override public Document<K, V> get(K key, GetOption... options) { return trace("get", () -> delegate.get(key, options)); } TracingKVStore(String creatorName, Tracer tracer, KVStore<K,V> delegate); } | TracingKVStore implements KVStore<K, V> { @Override public Document<K, V> get(K key, GetOption... options) { return trace("get", () -> delegate.get(key, options)); } TracingKVStore(String creatorName, Tracer tracer, KVStore<K,V> delegate); static TracingKVStore<K, V> of(String name, Tracer tracer, KVStore<K,V> delegate); @Override Document<K, V> get(K key, GetOption... options); @Override Iterable<Document<K, V>> get(List<K> keys, GetOption... options); @Override boolean contains(K key, ContainsOption... options); @Override Document<K, V> put(K key, V value, PutOption... options); @Override Iterable<Document<K, V>> find(FindOption... options); @Override Iterable<Document<K, V>> find(FindByRange<K> find, FindOption... options); @Override void delete(K key, DeleteOption... options); @Override KVAdmin getAdmin(); @Override String getName(); } | TracingKVStore implements KVStore<K, V> { @Override public Document<K, V> get(K key, GetOption... options) { return trace("get", () -> delegate.get(key, options)); } TracingKVStore(String creatorName, Tracer tracer, KVStore<K,V> delegate); static TracingKVStore<K, V> of(String name, Tracer tracer, KVStore<K,V> delegate); @Override Document<K, V> get(K key, GetOption... options); @Override Iterable<Document<K, V>> get(List<K> keys, GetOption... options); @Override boolean contains(K key, ContainsOption... options); @Override Document<K, V> put(K key, V value, PutOption... options); @Override Iterable<Document<K, V>> find(FindOption... options); @Override Iterable<Document<K, V>> find(FindByRange<K> find, FindOption... options); @Override void delete(K key, DeleteOption... options); @Override KVAdmin getAdmin(); @Override String getName(); static final String METHOD_TAG; static final String TABLE_TAG; static final String OPERATION_NAME; static final String CREATOR_TAG; } |
@Test public void testVoidReturnMethod() { setupLegitParentSpan(); underTest.delete("byebye"); verify(delegate).delete("byebye"); assertChildSpanMethod("delete"); } | @Override public void delete(K key, DeleteOption... options) { trace("delete", () -> delegate.delete(key, options)); } | TracingKVStore implements KVStore<K, V> { @Override public void delete(K key, DeleteOption... options) { trace("delete", () -> delegate.delete(key, options)); } } | TracingKVStore implements KVStore<K, V> { @Override public void delete(K key, DeleteOption... options) { trace("delete", () -> delegate.delete(key, options)); } TracingKVStore(String creatorName, Tracer tracer, KVStore<K,V> delegate); } | TracingKVStore implements KVStore<K, V> { @Override public void delete(K key, DeleteOption... options) { trace("delete", () -> delegate.delete(key, options)); } TracingKVStore(String creatorName, Tracer tracer, KVStore<K,V> delegate); static TracingKVStore<K, V> of(String name, Tracer tracer, KVStore<K,V> delegate); @Override Document<K, V> get(K key, GetOption... options); @Override Iterable<Document<K, V>> get(List<K> keys, GetOption... options); @Override boolean contains(K key, ContainsOption... options); @Override Document<K, V> put(K key, V value, PutOption... options); @Override Iterable<Document<K, V>> find(FindOption... options); @Override Iterable<Document<K, V>> find(FindByRange<K> find, FindOption... options); @Override void delete(K key, DeleteOption... options); @Override KVAdmin getAdmin(); @Override String getName(); } | TracingKVStore implements KVStore<K, V> { @Override public void delete(K key, DeleteOption... options) { trace("delete", () -> delegate.delete(key, options)); } TracingKVStore(String creatorName, Tracer tracer, KVStore<K,V> delegate); static TracingKVStore<K, V> of(String name, Tracer tracer, KVStore<K,V> delegate); @Override Document<K, V> get(K key, GetOption... options); @Override Iterable<Document<K, V>> get(List<K> keys, GetOption... options); @Override boolean contains(K key, ContainsOption... options); @Override Document<K, V> put(K key, V value, PutOption... options); @Override Iterable<Document<K, V>> find(FindOption... options); @Override Iterable<Document<K, V>> find(FindByRange<K> find, FindOption... options); @Override void delete(K key, DeleteOption... options); @Override KVAdmin getAdmin(); @Override String getName(); static final String METHOD_TAG; static final String TABLE_TAG; static final String OPERATION_NAME; static final String CREATOR_TAG; } |
@Test public void testValidateOptionsNull() { KVStoreOptionUtility.validateOptions((KVStore.PutOption[]) null); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testValidateOptionsEmpty() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testValidateOptionsSingleCreate() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{createOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testValidateOptionsMultipleCreate() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{createOption, createOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testValidateOptionsMultipleCreateWithIndex() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{createOption, indexPutOption, createOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testValidateOptionsCreateAndIndex() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{createOption, indexPutOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testValidateOptionsIndexAndCreate() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{indexPutOption, createOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testResetCatalogSearchCommand() throws Exception { getCurrentDremioDaemon().close(); ResetCatalogSearch.go(new String[] {}); final Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(getDACConfig().getConfig()); if (!providerOptional.isPresent()) { throw new Exception("No KVStore detected."); } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); final ConfigurationStore configStore = new ConfigurationStore(provider.asLegacy()); final ConfigurationEntry configurationEntry = configStore.get(CONFIG_KEY); assertEquals(configurationEntry, null); } } | static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); parse(args); if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Reset catalog search should be run on master node"); } final Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("Failed to complete catalog search reset. No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); AdminLogger.log("Resetting catalog search..."); final ConfigurationStore configStore = new ConfigurationStore(provider.asLegacy()); configStore.delete(CONFIG_KEY); AdminLogger.log("Catalog search reset will be completed in 1 minute after Dremio starts."); } } | ResetCatalogSearch { static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); parse(args); if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Reset catalog search should be run on master node"); } final Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("Failed to complete catalog search reset. No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); AdminLogger.log("Resetting catalog search..."); final ConfigurationStore configStore = new ConfigurationStore(provider.asLegacy()); configStore.delete(CONFIG_KEY); AdminLogger.log("Catalog search reset will be completed in 1 minute after Dremio starts."); } } } | ResetCatalogSearch { static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); parse(args); if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Reset catalog search should be run on master node"); } final Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("Failed to complete catalog search reset. No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); AdminLogger.log("Resetting catalog search..."); final ConfigurationStore configStore = new ConfigurationStore(provider.asLegacy()); configStore.delete(CONFIG_KEY); AdminLogger.log("Catalog search reset will be completed in 1 minute after Dremio starts."); } } } | ResetCatalogSearch { static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); parse(args); if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Reset catalog search should be run on master node"); } final Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("Failed to complete catalog search reset. No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); AdminLogger.log("Resetting catalog search..."); final ConfigurationStore configStore = new ConfigurationStore(provider.asLegacy()); configStore.delete(CONFIG_KEY); AdminLogger.log("Catalog search reset will be completed in 1 minute after Dremio starts."); } } static void main(String[] args); } | ResetCatalogSearch { static void go(String[] args) throws Exception { final DACConfig dacConfig = DACConfig.newConfig(); parse(args); if (!dacConfig.isMaster) { throw new UnsupportedOperationException("Reset catalog search should be run on master node"); } final Optional<LocalKVStoreProvider> providerOptional = CmdUtils.getKVStoreProvider(dacConfig.getConfig()); if (!providerOptional.isPresent()) { AdminLogger.log("Failed to complete catalog search reset. No KVStore detected."); return; } try (LocalKVStoreProvider provider = providerOptional.get()) { provider.start(); AdminLogger.log("Resetting catalog search..."); final ConfigurationStore configStore = new ConfigurationStore(provider.asLegacy()); configStore.delete(CONFIG_KEY); AdminLogger.log("Catalog search reset will be completed in 1 minute after Dremio starts."); } } static void main(String[] args); } |
@Test public void testValidateOptionsSingleVersion() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{versionOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testValidateOptionsMultipleVersion() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{versionOption, versionOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testValidateOptionsMultipleVersionWithIndex() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{versionOption, indexPutOption, versionOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testValidateOptionsVersionAndIndex() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{versionOption, indexPutOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testValidateOptionsIndexAndVersion() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{indexPutOption, versionOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testValidateOptionsConflict() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{createOption, versionOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testValidateOptionsConflictWithIndex() { KVStoreOptionUtility.validateOptions(new KVStore.PutOption[]{indexPutOption, createOption, versionOption}); } | public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void validateOptions(KVStore.KVStoreOption... options) { if (null == options || options.length <= 1) { return; } boolean foundVersion = false; boolean foundCreate = false; for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { if (foundCreate) { throw new IllegalArgumentException("Multiple CREATE PutOptions supplied."); } else { foundCreate = true; } } else if (option instanceof VersionOption) { if (foundVersion) { throw new IllegalArgumentException("Multiple Version PutOptions supplied."); } else { foundVersion = true; } } } if (foundCreate && foundVersion) { throw new IllegalArgumentException("Conflicting PutOptions supplied."); } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testIndexPutOptionNotSupportedNull() { KVStoreOptionUtility.checkIndexPutOptionIsNotUsed(); } | public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testIndexPutOptionNotSupportedEmpty() { KVStoreOptionUtility.checkIndexPutOptionIsNotUsed(new KVStore.PutOption[]{}); } | public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testIndexPutOptionNotSupportedSingleCreate() { KVStoreOptionUtility.checkIndexPutOptionIsNotUsed(new KVStore.PutOption[]{createOption}); } | public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void refreshSystemPluginsTest() throws Exception { SystemStoragePluginInitializer systemInitializer = new SystemStoragePluginInitializer(); SourceConfig c = new SourceConfig(); InternalFileConf conf = new InternalFileConf(); conf.connection = "classpath: conf.path = "/"; conf.isInternal = false; conf.propertyList = ImmutableList.of(new Property("abc", "bcd"), new Property("def", "123")); c.setName("mytest"); c.setConnectionConf(conf); c.setMetadataPolicy(CatalogService.NEVER_REFRESH_POLICY); systemInitializer.createOrUpdateSystemSource(catalogService, namespaceService, c); final CatalogServiceImpl catalog = (CatalogServiceImpl) catalogService; SourceConfig updatedC = new SourceConfig(); InternalFileConf updatedCConf = new InternalFileConf(); updatedCConf.connection = "file: updatedCConf.path = "/"; updatedCConf.isInternal = true; updatedC.setName("mytest"); updatedC.setConnectionConf(updatedCConf); updatedC.setMetadataPolicy(CatalogService.DEFAULT_METADATA_POLICY); final SourceConfig config = catalog.getManagedSource("mytest").getId().getClonedConfig(); InternalFileConf decryptedConf = (InternalFileConf) reader.getConnectionConf(config); systemInitializer.createOrUpdateSystemSource(catalogService, namespaceService, updatedC); final SourceConfig updatedConfig = catalog.getManagedSource("mytest").getId().getClonedConfig(); InternalFileConf decryptedUpdatedConfig = (InternalFileConf) reader.getConnectionConf(updatedConfig); assertNotNull(decryptedConf.getProperties()); assertEquals(2, decryptedConf.getProperties().size()); assertTrue(decryptedUpdatedConfig.getProperties().isEmpty()); assertNotEquals(config.getMetadataPolicy(), updatedConfig.getMetadataPolicy()); assertNotEquals(decryptedConf.getConnection(), decryptedUpdatedConfig.getConnection()); assertEquals("file: assertNotEquals(decryptedConf.isInternal, decryptedUpdatedConfig.isInternal); assertEquals(decryptedConf.path, decryptedUpdatedConfig.path); assertNotEquals(config.getTag(), updatedConfig.getTag()); SourceConfig updatedC2 = new SourceConfig(); InternalFileConf updatedCConf2 = new InternalFileConf(); updatedCConf2.connection = "file: updatedCConf2.path = "/"; updatedCConf2.isInternal = true; updatedC2.setName("mytest"); updatedC2.setConnectionConf(updatedCConf2); updatedC2.setMetadataPolicy(CatalogService.DEFAULT_METADATA_POLICY); systemInitializer.createOrUpdateSystemSource(catalogService, namespaceService, updatedC2); final SourceConfig updatedConfig2 = catalog.getManagedSource("mytest").getId().getClonedConfig(); InternalFileConf decryptedConf2 = (InternalFileConf) reader.getConnectionConf(updatedConfig2); assertTrue(decryptedConf2.getProperties().isEmpty()); assertEquals(updatedConfig.getTag(), updatedConfig2.getTag()); catalog.deleteSource("mytest"); assertNull(catalog.getManagedSource("myTest")); } | @VisibleForTesting void createOrUpdateSystemSource(final CatalogService catalogService, final NamespaceService ns, final SourceConfig config) throws Exception { try { config.setAllowCrossSourceSelection(true); final boolean isCreated = catalogService.createSourceIfMissingWithThrow(config); if (isCreated) { return; } } catch (ConcurrentModificationException ex) { logger.info("Two source creations occurred simultaneously, ignoring the failed one.", ex); } final NamespaceKey nsKey = new NamespaceKey(config.getName()); final SourceConfig oldConfig = ns.getSource(nsKey); final SourceConfig updatedConfig = config; updatedConfig .setId(oldConfig.getId()) .setCtime(oldConfig.getCtime()) .setTag(oldConfig.getTag()) .setConfigOrdinal(oldConfig.getConfigOrdinal()); if (oldConfig.equals(updatedConfig)) { return; } ((CatalogServiceImpl) catalogService).getSystemUserCatalog().updateSource(updatedConfig); } | SystemStoragePluginInitializer implements Initializer<Void> { @VisibleForTesting void createOrUpdateSystemSource(final CatalogService catalogService, final NamespaceService ns, final SourceConfig config) throws Exception { try { config.setAllowCrossSourceSelection(true); final boolean isCreated = catalogService.createSourceIfMissingWithThrow(config); if (isCreated) { return; } } catch (ConcurrentModificationException ex) { logger.info("Two source creations occurred simultaneously, ignoring the failed one.", ex); } final NamespaceKey nsKey = new NamespaceKey(config.getName()); final SourceConfig oldConfig = ns.getSource(nsKey); final SourceConfig updatedConfig = config; updatedConfig .setId(oldConfig.getId()) .setCtime(oldConfig.getCtime()) .setTag(oldConfig.getTag()) .setConfigOrdinal(oldConfig.getConfigOrdinal()); if (oldConfig.equals(updatedConfig)) { return; } ((CatalogServiceImpl) catalogService).getSystemUserCatalog().updateSource(updatedConfig); } } | SystemStoragePluginInitializer implements Initializer<Void> { @VisibleForTesting void createOrUpdateSystemSource(final CatalogService catalogService, final NamespaceService ns, final SourceConfig config) throws Exception { try { config.setAllowCrossSourceSelection(true); final boolean isCreated = catalogService.createSourceIfMissingWithThrow(config); if (isCreated) { return; } } catch (ConcurrentModificationException ex) { logger.info("Two source creations occurred simultaneously, ignoring the failed one.", ex); } final NamespaceKey nsKey = new NamespaceKey(config.getName()); final SourceConfig oldConfig = ns.getSource(nsKey); final SourceConfig updatedConfig = config; updatedConfig .setId(oldConfig.getId()) .setCtime(oldConfig.getCtime()) .setTag(oldConfig.getTag()) .setConfigOrdinal(oldConfig.getConfigOrdinal()); if (oldConfig.equals(updatedConfig)) { return; } ((CatalogServiceImpl) catalogService).getSystemUserCatalog().updateSource(updatedConfig); } } | SystemStoragePluginInitializer implements Initializer<Void> { @VisibleForTesting void createOrUpdateSystemSource(final CatalogService catalogService, final NamespaceService ns, final SourceConfig config) throws Exception { try { config.setAllowCrossSourceSelection(true); final boolean isCreated = catalogService.createSourceIfMissingWithThrow(config); if (isCreated) { return; } } catch (ConcurrentModificationException ex) { logger.info("Two source creations occurred simultaneously, ignoring the failed one.", ex); } final NamespaceKey nsKey = new NamespaceKey(config.getName()); final SourceConfig oldConfig = ns.getSource(nsKey); final SourceConfig updatedConfig = config; updatedConfig .setId(oldConfig.getId()) .setCtime(oldConfig.getCtime()) .setTag(oldConfig.getTag()) .setConfigOrdinal(oldConfig.getConfigOrdinal()); if (oldConfig.equals(updatedConfig)) { return; } ((CatalogServiceImpl) catalogService).getSystemUserCatalog().updateSource(updatedConfig); } @Override Void initialize(BindingProvider provider); } | SystemStoragePluginInitializer implements Initializer<Void> { @VisibleForTesting void createOrUpdateSystemSource(final CatalogService catalogService, final NamespaceService ns, final SourceConfig config) throws Exception { try { config.setAllowCrossSourceSelection(true); final boolean isCreated = catalogService.createSourceIfMissingWithThrow(config); if (isCreated) { return; } } catch (ConcurrentModificationException ex) { logger.info("Two source creations occurred simultaneously, ignoring the failed one.", ex); } final NamespaceKey nsKey = new NamespaceKey(config.getName()); final SourceConfig oldConfig = ns.getSource(nsKey); final SourceConfig updatedConfig = config; updatedConfig .setId(oldConfig.getId()) .setCtime(oldConfig.getCtime()) .setTag(oldConfig.getTag()) .setConfigOrdinal(oldConfig.getConfigOrdinal()); if (oldConfig.equals(updatedConfig)) { return; } ((CatalogServiceImpl) catalogService).getSystemUserCatalog().updateSource(updatedConfig); } @Override Void initialize(BindingProvider provider); } |
@Test public void testIndexPutOptionNotSupportedSingleVersion() { KVStoreOptionUtility.checkIndexPutOptionIsNotUsed(new KVStore.PutOption[]{versionOption}); } | public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testIndexPutOptionNotSupportedCreateAndVersion() { KVStoreOptionUtility.checkIndexPutOptionIsNotUsed(new KVStore.PutOption[]{createOption, versionOption}); } | public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testIndexPutOptionNotSupportedIndexPutOptionFound() { KVStoreOptionUtility.checkIndexPutOptionIsNotUsed(new KVStore.PutOption[]{indexPutOption}); } | public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testIndexPutOptionNotSupportedIndexPutOptionFoundAmongMany() { KVStoreOptionUtility.checkIndexPutOptionIsNotUsed(new KVStore.PutOption[]{createOption, indexPutOption, versionOption}); } | public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options) { if (null == options || options.length == 0) { return; } for (KVStore.KVStoreOption option : options) { if (option instanceof IndexPutOption) { throw new IllegalArgumentException("IndexPutOption not supported."); } } } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testGetCreateOrVersionOptionNull() { final Optional<KVStore.PutOption> ret = KVStoreOptionUtility.getCreateOrVersionOption(); assertFalse(ret.isPresent()); } | public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testGetCreateOrVersionOptionEmpty() { final Optional<KVStore.PutOption> ret = KVStoreOptionUtility.getCreateOrVersionOption(new KVStore.PutOption[]{}); assertFalse(ret.isPresent()); } | public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testGetCreateOrVersionOptionSingleCreate() { final Optional<KVStore.PutOption> ret = KVStoreOptionUtility.getCreateOrVersionOption(new KVStore.PutOption[]{createOption}); assertEquals(createOption, ret.get()); } | public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testGetCreateOrVersionOptionSingleVersion() { final Optional<KVStore.PutOption> ret = KVStoreOptionUtility.getCreateOrVersionOption(new KVStore.PutOption[]{versionOption}); assertEquals(versionOption, ret.get()); } | public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test(expected = IllegalArgumentException.class) public void testGetCreateOrVersionOptionCreateAndVersion() { KVStoreOptionUtility.getCreateOrVersionOption(new KVStore.PutOption[]{createOption, versionOption}); } | public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testGetCreateOrVersionOptionIndexPutOptionFound() { final Optional<KVStore.PutOption> ret = KVStoreOptionUtility.getCreateOrVersionOption(new KVStore.PutOption[]{indexPutOption}); assertFalse(ret.isPresent()); } | public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testGetStartOfLastMonth() { LocalDate dateLastMonth = LocalDate.now().minusMonths(1); long startOfLastMonth = DateUtils.getStartOfLastMonth(); LocalDate dateStartOfLastMonth = DateUtils.fromEpochMillis(startOfLastMonth); assertEquals(dateLastMonth.getMonthValue(), dateStartOfLastMonth.getMonthValue()); assertEquals(dateLastMonth.getYear(), dateStartOfLastMonth.getYear()); assertEquals(1, dateStartOfLastMonth.getDayOfMonth()); } | public static long getStartOfLastMonth() { LocalDate now = LocalDate.now(); LocalDate targetDate = now.minusDays(now.getDayOfMonth() - 1).minusMonths(1); Instant instant = targetDate.atStartOfDay().toInstant(ZoneOffset.UTC); return instant.toEpochMilli(); } | DateUtils { public static long getStartOfLastMonth() { LocalDate now = LocalDate.now(); LocalDate targetDate = now.minusDays(now.getDayOfMonth() - 1).minusMonths(1); Instant instant = targetDate.atStartOfDay().toInstant(ZoneOffset.UTC); return instant.toEpochMilli(); } } | DateUtils { public static long getStartOfLastMonth() { LocalDate now = LocalDate.now(); LocalDate targetDate = now.minusDays(now.getDayOfMonth() - 1).minusMonths(1); Instant instant = targetDate.atStartOfDay().toInstant(ZoneOffset.UTC); return instant.toEpochMilli(); } } | DateUtils { public static long getStartOfLastMonth() { LocalDate now = LocalDate.now(); LocalDate targetDate = now.minusDays(now.getDayOfMonth() - 1).minusMonths(1); Instant instant = targetDate.atStartOfDay().toInstant(ZoneOffset.UTC); return instant.toEpochMilli(); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } | DateUtils { public static long getStartOfLastMonth() { LocalDate now = LocalDate.now(); LocalDate targetDate = now.minusDays(now.getDayOfMonth() - 1).minusMonths(1); Instant instant = targetDate.atStartOfDay().toInstant(ZoneOffset.UTC); return instant.toEpochMilli(); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } |
@Test(expected = IllegalArgumentException.class) public void testGetCreateOrVersionOptionPutOptionFoundAmongMany() { KVStoreOptionUtility.getCreateOrVersionOption(new KVStore.PutOption[]{createOption, indexPutOption, versionOption}); } | public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options) { validateOptions(options); if (null == options || options.length == 0) { return Optional.empty(); } for (KVStore.KVStoreOption option : options) { if (option == KVStore.PutOption.CREATE) { return Optional.of((KVStore.PutOption) option); } else if (option instanceof VersionOption) { return Optional.of((VersionOption) option); } } return Optional.empty(); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testRemoveIndexPutOption() { testRemoveIndexPutOptions( new KVStore.PutOption[]{indexPutOption}, new KVStore.PutOption[]{}); } | public static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options) { if (null == options) { return null; } return Arrays .stream(options) .filter(option -> !(option instanceof IndexPutOption)) .toArray(KVStore.PutOption[]::new); } | KVStoreOptionUtility { public static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options) { if (null == options) { return null; } return Arrays .stream(options) .filter(option -> !(option instanceof IndexPutOption)) .toArray(KVStore.PutOption[]::new); } } | KVStoreOptionUtility { public static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options) { if (null == options) { return null; } return Arrays .stream(options) .filter(option -> !(option instanceof IndexPutOption)) .toArray(KVStore.PutOption[]::new); } } | KVStoreOptionUtility { public static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options) { if (null == options) { return null; } return Arrays .stream(options) .filter(option -> !(option instanceof IndexPutOption)) .toArray(KVStore.PutOption[]::new); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } | KVStoreOptionUtility { public static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options) { if (null == options) { return null; } return Arrays .stream(options) .filter(option -> !(option instanceof IndexPutOption)) .toArray(KVStore.PutOption[]::new); } static void validateOptions(KVStore.KVStoreOption... options); static Optional<KVStore.PutOption> getCreateOrVersionOption(KVStore.KVStoreOption... options); static void checkIndexPutOptionIsNotUsed(KVStore.KVStoreOption... options); static KVStore.PutOption[] removeIndexPutOption(KVStore.PutOption... options); } |
@Test public void testParse() throws InvalidProtocolBufferException { final UnknownFieldSet term1 = UnknownFieldSet.newBuilder() .addField(SearchQuery.Term.FIELD_FIELD_NUMBER, Field.newBuilder().addLengthDelimited(ByteString.copyFromUtf8("foo")).build()) .addField(SearchQuery.Term.VALUE_FIELD_NUMBER, Field.newBuilder().addLengthDelimited(ByteString.copyFromUtf8("bar")).build()) .build(); final UnknownFieldSet sq1 = UnknownFieldSet.newBuilder() .addField(SearchQuery.TYPE_FIELD_NUMBER, Field.newBuilder().addVarint(SearchQuery.Type.TERM_VALUE).build()) .addField(SearchQuery.TERM_FIELD_NUMBER, Field.newBuilder().addGroup(term1).build()) .build(); final UnknownFieldSet term2 = UnknownFieldSet.newBuilder() .addField(SearchQuery.Term.FIELD_FIELD_NUMBER, Field.newBuilder().addLengthDelimited(ByteString.copyFromUtf8("foo")).build()) .addField(SearchQuery.Term.VALUE_FIELD_NUMBER, Field.newBuilder().addLengthDelimited(ByteString.copyFromUtf8("baz")).build()) .build(); final UnknownFieldSet sq2 = UnknownFieldSet.newBuilder() .addField(SearchQuery.TYPE_FIELD_NUMBER, Field.newBuilder().addVarint(SearchQuery.Type.TERM_VALUE).build()) .addField(SearchQuery.TERM_FIELD_NUMBER, Field.newBuilder().addGroup(term2).build()) .build(); final UnknownFieldSet bool = UnknownFieldSet.newBuilder() .addField(SearchQuery.Boolean.OP_FIELD_NUMBER, Field.newBuilder().addVarint(SearchQuery.BooleanOp.AND_VALUE).build()) .addField(SearchQuery.Boolean.CLAUSES_FIELD_NUMBER, Field.newBuilder().addGroup(sq1).addGroup(sq2).build()) .build(); final SearchQuery query = SearchQuery.newBuilder() .setType(SearchQuery.Type.BOOLEAN) .setUnknownFields(UnknownFieldSet.newBuilder().addField(SearchQuery.BOOLEAN_FIELD_NUMBER, Field.newBuilder().addGroup(bool).build()).build()) .build(); final SearchQuery expected = SearchQuery.newBuilder() .setType(SearchQuery.Type.BOOLEAN) .setBoolean( SearchQuery.Boolean.newBuilder() .setOp(SearchQuery.BooleanOp.AND) .addClauses(SearchQuery.newBuilder() .setType(SearchQuery.Type.TERM).setTerm(Term.newBuilder().setField("foo").setValue("bar"))) .addClauses(SearchQuery.newBuilder() .setType(SearchQuery.Type.TERM).setTerm(Term.newBuilder().setField("foo").setValue("baz"))) ) .build(); assertThat(LegacyProtobufSerializer.parseFrom(SearchQuery.PARSER, query.toByteString()), is(equalTo(expected))); } | public static <M extends Message> M parseFrom(Parser<M> parser, ByteString bytes) throws InvalidProtocolBufferException { return rewriteProtostuff(parser.parseFrom(bytes)); } | LegacyProtobufSerializer extends ProtobufSerializer<T> { public static <M extends Message> M parseFrom(Parser<M> parser, ByteString bytes) throws InvalidProtocolBufferException { return rewriteProtostuff(parser.parseFrom(bytes)); } } | LegacyProtobufSerializer extends ProtobufSerializer<T> { public static <M extends Message> M parseFrom(Parser<M> parser, ByteString bytes) throws InvalidProtocolBufferException { return rewriteProtostuff(parser.parseFrom(bytes)); } LegacyProtobufSerializer(Class<T> clazz, Parser<T> parser); } | LegacyProtobufSerializer extends ProtobufSerializer<T> { public static <M extends Message> M parseFrom(Parser<M> parser, ByteString bytes) throws InvalidProtocolBufferException { return rewriteProtostuff(parser.parseFrom(bytes)); } LegacyProtobufSerializer(Class<T> clazz, Parser<T> parser); @Override T revert(byte[] bytes); static M parseFrom(Parser<M> parser, ByteString bytes); static M parseFrom(Parser<M> parser, byte[] bytes); static M parseFrom(Parser<M> parser, ByteBuffer bytes); } | LegacyProtobufSerializer extends ProtobufSerializer<T> { public static <M extends Message> M parseFrom(Parser<M> parser, ByteString bytes) throws InvalidProtocolBufferException { return rewriteProtostuff(parser.parseFrom(bytes)); } LegacyProtobufSerializer(Class<T> clazz, Parser<T> parser); @Override T revert(byte[] bytes); static M parseFrom(Parser<M> parser, ByteString bytes); static M parseFrom(Parser<M> parser, byte[] bytes); static M parseFrom(Parser<M> parser, ByteBuffer bytes); } |
@Test public void handleGoalWithNoEntry(){ ReflectionId reflectionId = new ReflectionId("r_id"); ReflectionGoalHash reflectionGoalHash = new ReflectionGoalHash("MY_HASH"); String reflectionGoalName = "name"; String dataSetId = "dataSetId"; String tag = "rgTag"; ReflectionGoal reflectionGoal = new ReflectionGoal() .setId(reflectionId) .setArrowCachingEnabled(true) .setName(reflectionGoalName) .setTag(tag) .setType(ReflectionType.EXTERNAL) .setDatasetId(dataSetId); Subject subject = new Subject(); when(subject.reflectionStore.get(reflectionId)).thenReturn(null); when(subject.reflectionGoalChecker.calculateReflectionGoalVersion(reflectionGoal)).thenReturn(reflectionGoalHash); subject.reflectionManager.handleGoal(reflectionGoal); verify(subject.reflectionStore).get(reflectionId); verify(subject.reflectionGoalChecker).calculateReflectionGoalVersion(reflectionGoal); verify(subject.reflectionStore).save( new ReflectionEntry() .setId(reflectionId) .setReflectionGoalHash(reflectionGoalHash) .setDatasetId(dataSetId) .setState(REFRESH) .setGoalVersion(tag) .setType(ReflectionType.EXTERNAL) .setName(reflectionGoalName) .setArrowCachingEnabled(true) ); verifyNoMoreInteractions(subject.reflectionStore); } | @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } |
@Test public void handleGoalWithEntryButNothingHasChanged(){ ReflectionId reflectionId = new ReflectionId("r_id"); ReflectionGoalHash reflectionGoalHash = new ReflectionGoalHash("MY_HASH"); String reflectionGoalName = "name"; String dataSetId = "dataSetId"; ReflectionGoal reflectionGoal = new ReflectionGoal() .setId(reflectionId) .setArrowCachingEnabled(true) .setName(reflectionGoalName) .setType(ReflectionType.EXTERNAL) .setDatasetId(dataSetId) .setArrowCachingEnabled(true); ReflectionEntry reflectionEntry = new ReflectionEntry() .setArrowCachingEnabled(true) .setId(reflectionId) .setReflectionGoalHash(reflectionGoalHash); Subject subject = new Subject(); when(subject.reflectionStore.get(reflectionId)).thenReturn(reflectionEntry); when(subject.reflectionGoalChecker.isEqual(reflectionGoal, reflectionEntry)) .thenReturn(true); subject.reflectionManager.handleGoal(reflectionGoal); verify(subject.reflectionStore).get(reflectionId); verify(subject.reflectionGoalChecker).isEqual(reflectionGoal, reflectionEntry); verifyNoMoreInteractions(subject.reflectionStore); } | @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } |
@Test public void handleGoalWithEntryButHashHasNotChangedAndBoostHasChanged(){ ReflectionId reflectionId = new ReflectionId("r_id"); ReflectionGoalHash reflectionGoalHash = new ReflectionGoalHash("MY_HASH"); String goalTag = "goal_tag"; String reflectionGoalName = "name"; String dataSetId = "dataSetId"; ReflectionGoal reflectionGoal = new ReflectionGoal() .setArrowCachingEnabled(true) .setDatasetId(dataSetId) .setId(reflectionId) .setName(reflectionGoalName) .setTag(goalTag) .setType(ReflectionType.EXTERNAL); ReflectionEntry reflectionEntry = new ReflectionEntry() .setArrowCachingEnabled(false) .setId(reflectionId) .setName("oldName") .setGoalVersion("old_tag") .setReflectionGoalHash(reflectionGoalHash) .setState(ReflectionState.ACTIVE); Subject subject = new Subject(); when(subject.reflectionStore.get(reflectionId)).thenReturn(reflectionEntry); when(subject.reflectionGoalChecker.checkHash(reflectionGoal, reflectionEntry)) .thenReturn(true); when(subject.materializationStore.find(reflectionId)).thenReturn(Collections.emptyList()); subject.reflectionManager.handleGoal(reflectionGoal); verify(subject.reflectionStore).get(reflectionId); verify(subject.reflectionGoalChecker).checkHash(reflectionGoal, reflectionEntry); verify(subject.reflectionStore).save(reflectionEntry); verifyNoMoreInteractions(subject.reflectionStore); assertEquals(ReflectionState.ACTIVE, reflectionEntry.getState()); assertEquals(true, reflectionEntry.getArrowCachingEnabled()); assertEquals(reflectionGoalName, reflectionEntry.getName()); assertEquals(goalTag, reflectionEntry.getGoalVersion()); } | @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } |
@Test public void handleGoalTagChangedAndEntryIsInFailedState(){ ReflectionId reflectionId = new ReflectionId("r_id"); ReflectionGoalHash reflectionGoalHash = new ReflectionGoalHash("MY_HASH"); String goalTag = "goal_tag"; String reflectionGoalName = "name"; String dataSetId = "dataSetId"; ReflectionGoal reflectionGoal = new ReflectionGoal() .setArrowCachingEnabled(true) .setDatasetId(dataSetId) .setId(reflectionId) .setName(reflectionGoalName) .setTag(goalTag) .setState(ReflectionGoalState.ENABLED) .setType(ReflectionType.EXTERNAL); ReflectionEntry reflectionEntry = new ReflectionEntry() .setArrowCachingEnabled(false) .setId(reflectionId) .setName("oldName") .setGoalVersion("old_tag") .setReflectionGoalHash(reflectionGoalHash) .setState(ReflectionState.FAILED) .setNumFailures(3); Subject subject = new Subject(); when(subject.reflectionStore.get(reflectionId)).thenReturn(reflectionEntry); when(subject.reflectionGoalChecker.checkHash(reflectionGoal, reflectionEntry)) .thenReturn(true); when(subject.materializationStore.find(reflectionId)).thenReturn(Collections.emptyList()); subject.reflectionManager.handleGoal(reflectionGoal); verify(subject.reflectionStore).get(reflectionId); verify(subject.reflectionGoalChecker).checkHash(reflectionGoal, reflectionEntry); verify(subject.reflectionStore).save(reflectionEntry); verifyNoMoreInteractions(subject.reflectionStore); assertEquals(ReflectionState.UPDATE, reflectionEntry.getState()); assertEquals(Integer.valueOf(0), reflectionEntry.getNumFailures()); assertEquals(true, reflectionEntry.getArrowCachingEnabled()); assertEquals(reflectionGoalName, reflectionEntry.getName()); assertEquals(goalTag, reflectionEntry.getGoalVersion()); } | @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } |
@Test public void handleGoalWithEntryButHashHasChanged(){ ReflectionId reflectionId = new ReflectionId("r_id"); ReflectionGoalHash reflectionGoalHash = new ReflectionGoalHash("MY_HASH"); String reflectionGoalName = "name"; String goalTag = "goalTag"; String dataSetId = "dataSetId"; ReflectionGoal reflectionGoal = new ReflectionGoal() .setArrowCachingEnabled(true) .setDatasetId(dataSetId) .setId(reflectionId) .setName(reflectionGoalName) .setTag(goalTag) .setType(ReflectionType.EXTERNAL); ReflectionEntry reflectionEntry = new ReflectionEntry() .setArrowCachingEnabled(false) .setId(reflectionId) .setGoalVersion("old tag") .setReflectionGoalHash(new ReflectionGoalHash("xxx")) .setState(ReflectionState.ACTIVE); Subject subject = new Subject(); when(subject.reflectionStore.get(reflectionId)).thenReturn(reflectionEntry); when(subject.reflectionGoalChecker.isEqual(reflectionGoal, reflectionEntry)) .thenReturn(false); when(subject.reflectionGoalChecker.checkHash(reflectionGoal, reflectionEntry)) .thenReturn(false); when(subject.reflectionGoalChecker.calculateReflectionGoalVersion(reflectionGoal)).thenReturn(reflectionGoalHash); when(subject.materializationStore.find(reflectionId)).thenReturn(Collections.emptyList()); subject.reflectionManager.handleGoal(reflectionGoal); verify(subject.reflectionStore).get(reflectionId); verify(subject.reflectionGoalChecker).checkHash(reflectionGoal, reflectionEntry); verify(subject.reflectionStore).save(reflectionEntry); verifyNoMoreInteractions(subject.reflectionStore); assertEquals(true, reflectionEntry.getArrowCachingEnabled()); assertEquals(goalTag, reflectionEntry.getGoalVersion()); assertEquals(reflectionGoalName, reflectionEntry.getName()); assertEquals(reflectionGoalHash, reflectionEntry.getReflectionGoalHash()); assertEquals(ReflectionState.UPDATE, reflectionEntry.getState()); } | @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } | ReflectionManager implements Runnable { @VisibleForTesting void handleGoal(ReflectionGoal goal) { final ReflectionEntry entry = reflectionStore.get(goal.getId()); if (entry == null) { if (goal.getState() == ReflectionGoalState.ENABLED) { reflectionStore.save(create(goal)); } } else if (reflectionGoalChecker.isEqual(goal, entry)) { return; } else if(reflectionGoalChecker.checkHash(goal, entry)){ updateThatHasChangedEntry(goal, entry); for (Materialization materialization : materializationStore.find(entry.getId())) { if (!Objects.equals(materialization.getArrowCachingEnabled(), goal.getArrowCachingEnabled())) { materializationStore.save( materialization .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setReflectionGoalVersion(goal.getTag()) ); } } } else { logger.debug("reflection goal {} updated. state {} -> {}", getId(goal), entry.getState(), goal.getState()); cancelRefreshJobIfAny(entry); final boolean enabled = goal.getState() == ReflectionGoalState.ENABLED; entry.setState(enabled ? UPDATE : DEPRECATE) .setArrowCachingEnabled(goal.getArrowCachingEnabled()) .setGoalVersion(goal.getTag()) .setName(goal.getName()) .setReflectionGoalHash(reflectionGoalChecker.calculateReflectionGoalVersion(goal)); reflectionStore.save(entry); } } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } |
@Test public void testSyncDoesNotUpdateReflectionWhenOnlyBoostIsToggle(){ ReflectionId reflectionId = new ReflectionId("r_id"); ReflectionGoalHash reflectionGoalHash = new ReflectionGoalHash("MY_HASH"); String reflectionGoalName = "name"; String dataSetId = "dataSetId"; ReflectionGoal reflectionGoal = new ReflectionGoal() .setId(reflectionId) .setArrowCachingEnabled(true) .setDatasetId(dataSetId) .setType(ReflectionType.EXTERNAL) .setState(ReflectionGoalState.ENABLED); ReflectionEntry reflectionEntry = new ReflectionEntry() .setId(reflectionId) .setReflectionGoalHash(reflectionGoalHash) .setArrowCachingEnabled(false) .setState(ReflectionState.ACTIVE); Materialization materialization = new Materialization() .setArrowCachingEnabled(false); DatasetConfig datasetConfig = new DatasetConfig(); Subject subject = new Subject(); when(subject.dependencyManager.shouldRefresh(reflectionEntry, 5555L)).thenReturn(false); when(subject.externalReflectionStore.getExternalReflections()).thenReturn(emptyList()); when(subject.materializationStore.find(reflectionId)).thenReturn(singletonList(materialization)); when(subject.materializationStore.getAllExpiredWhen(anyLong())).thenReturn(emptyList()); when(subject.materializationStore.getDeletableEntriesModifiedBefore(anyLong(), anyInt())).thenReturn(emptyList()); when(subject.namespaceService.findDatasetByUUID(dataSetId)).thenReturn(datasetConfig); when(subject.optionManager.getOption(ReflectionOptions.NO_DEPENDENCY_REFRESH_PERIOD_SECONDS)).thenReturn(5555L); when(subject.reflectionStore.get(reflectionId)).thenReturn(reflectionEntry); when(subject.reflectionStore.find()).thenReturn(singletonList(reflectionEntry)); when(subject.reflectionGoalChecker.isEqual(reflectionGoal, reflectionEntry)).thenReturn(false); when(subject.reflectionGoalChecker.checkHash(reflectionGoal,reflectionEntry)).thenReturn(true); when(subject.userStore.getAllNotDeleted()).thenReturn(singletonList(reflectionGoal)); when(subject.userStore.getDeletedBefore(anyLong())).thenReturn(emptyList()); when(subject.userStore.getModifiedOrCreatedSince(anyLong())).thenReturn(singletonList(reflectionGoal)); subject.reflectionManager.sync(); verify(subject.materializationStore).save(materialization); verify(subject.reflectionStore).get(reflectionId); verify(subject.reflectionStore).find(); verify(subject.reflectionStore).save(reflectionEntry); verify(subject.reflectionGoalChecker).checkHash(reflectionGoal, reflectionEntry); verifyNoMoreInteractions(subject.reflectionStore); verifyNoMoreInteractions(subject.refreshStartHandler); assertEquals(reflectionGoalHash, reflectionEntry.getReflectionGoalHash()); assertEquals(true, reflectionEntry.getArrowCachingEnabled()); assertEquals(true, materialization.getArrowCachingEnabled()); assertEquals(ReflectionState.ACTIVE, reflectionEntry.getState()); } | @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } |
@Test public void testSyncDoesUpdateReflectionWhenChanged(){ ReflectionId reflectionId = new ReflectionId("r_id"); MaterializationId materializationId = new MaterializationId("m_id"); ReflectionGoalHash reflectionGoalHash = new ReflectionGoalHash("MY_HASH"); JobId materializationJobId = new JobId("m_job_id"); String dataSetId = "dataSetId"; ReflectionGoal reflectionGoal = new ReflectionGoal() .setId(reflectionId) .setArrowCachingEnabled(true) .setDatasetId(dataSetId) .setType(ReflectionType.EXTERNAL) .setState(ReflectionGoalState.ENABLED); ReflectionEntry reflectionEntry = new ReflectionEntry() .setId(reflectionId) .setReflectionGoalHash(reflectionGoalHash) .setArrowCachingEnabled(false) .setState(ReflectionState.ACTIVE); Materialization materialization = new Materialization() .setId(materializationId) .setReflectionId(reflectionId) .setArrowCachingEnabled(false); DatasetConfig datasetConfig = new DatasetConfig(); Subject subject = new Subject(); when(subject.dependencyManager.shouldRefresh(reflectionEntry, 5555L)).thenReturn(false); when(subject.externalReflectionStore.getExternalReflections()).thenReturn(emptyList()); when(subject.materializationStore.find(reflectionId)).thenReturn(singletonList(materialization)); when(subject.materializationStore.getAllExpiredWhen(anyLong())).thenReturn(emptyList()); when(subject.materializationStore.getDeletableEntriesModifiedBefore(anyLong(), anyInt())).thenReturn(emptyList()); when(subject.materializationStore.getAllDone(reflectionId)).thenReturn(singletonList(materialization)); when(subject.namespaceService.findDatasetByUUID(dataSetId)).thenReturn(datasetConfig); when(subject.optionManager.getOption(ReflectionOptions.NO_DEPENDENCY_REFRESH_PERIOD_SECONDS)).thenReturn(5555L); when(subject.reflectionStore.get(reflectionId)).thenReturn(reflectionEntry); when(subject.reflectionStore.find()).thenReturn(singletonList(reflectionEntry)); when(subject.reflectionGoalChecker.isEqual(reflectionGoal, reflectionEntry)).thenReturn(false); when(subject.reflectionGoalChecker.checkHash(reflectionGoal,reflectionEntry)).thenReturn(false); when(subject.reflectionGoalChecker.calculateReflectionGoalVersion(reflectionGoal)).thenReturn(reflectionGoalHash); when(subject.refreshStartHandler.startJob(any(), anyLong())).thenReturn(materializationJobId); when(subject.sabotContext.getExecutors()).thenReturn(singletonList(null)); when(subject.userStore.getAllNotDeleted()).thenReturn(singletonList(reflectionGoal)); when(subject.userStore.getDeletedBefore(anyLong())).thenReturn(emptyList()); when(subject.userStore.getModifiedOrCreatedSince(anyLong())).thenReturn(singletonList(reflectionGoal)); subject.reflectionManager.sync(); verify(subject.reflectionStore).get(reflectionId); verify(subject.reflectionStore).find(); verify(subject.reflectionStore, times(2)).save(reflectionEntry); verify(subject.reflectionGoalChecker).checkHash(reflectionGoal, reflectionEntry); verify(subject.descriptorCache).invalidate(materializationId); verify(subject.refreshStartHandler).startJob(any(), anyLong()); verifyNoMoreInteractions(subject.reflectionStore); verifyNoMoreInteractions(subject.refreshStartHandler); assertEquals(reflectionGoalHash, reflectionEntry.getReflectionGoalHash()); assertEquals(true, reflectionEntry.getArrowCachingEnabled()); assertEquals(false, materialization.getArrowCachingEnabled()); assertEquals(0 , reflectionEntry.getNumFailures().intValue()); assertEquals(ReflectionState.REFRESHING, reflectionEntry.getState()); assertEquals(MaterializationState.DEPRECATED, materialization.getState()); } | @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } | ReflectionManager implements Runnable { @VisibleForTesting void sync(){ long lastWakeupTime = System.currentTimeMillis(); final long previousLastWakeupTime = lastWakeupTime - WAKEUP_OVERLAP_MS; final long deletionGracePeriod = optionManager.getOption(REFLECTION_DELETION_GRACE_PERIOD) * 1000; final long deletionThreshold = System.currentTimeMillis() - deletionGracePeriod; final int numEntriesToDelete = (int) optionManager.getOption(REFLECTION_DELETION_NUM_ENTRIES); handleReflectionsToUpdate(); handleDeletedDatasets(); handleGoals(previousLastWakeupTime); handleEntries(); deleteDeprecatedMaterializations(deletionThreshold, numEntriesToDelete); deprecateMaterializations(); deleteDeprecatedGoals(deletionThreshold); this.lastWakeupTime = lastWakeupTime; } ReflectionManager(SabotContext sabotContext, JobsService jobsService, NamespaceService namespaceService,
OptionManager optionManager, ReflectionGoalsStore userStore, ReflectionEntriesStore reflectionStore,
ExternalReflectionStore externalReflectionStore, MaterializationStore materializationStore,
DependencyManager dependencyManager, DescriptorCache descriptorCache,
Set<ReflectionId> reflectionsToUpdate, WakeUpCallback wakeUpCallback,
Supplier<ExpansionHelper> expansionHelper, BufferAllocator allocator, Path accelerationBasePath,
ReflectionGoalChecker reflectionGoalChecker, RefreshStartHandler refreshStartHandler); @Override void run(); long getLastWakeupTime(); } |
@Test public void testGetLastSundayDate() { LocalDate testDate1 = LocalDate.parse("2020-03-29"); LocalDate date1LastSunday = DateUtils.getLastSundayDate(testDate1); assertEquals(testDate1, date1LastSunday); LocalDate testDate2 = LocalDate.parse("2020-03-28"); LocalDate date2LastSunday = DateUtils.getLastSundayDate(testDate2); assertEquals(LocalDate.parse("2020-03-22"), date2LastSunday); } | public static LocalDate getLastSundayDate(final LocalDate dateWithinWeek) { int dayOfWeek = dateWithinWeek.getDayOfWeek().getValue(); dayOfWeek = (dayOfWeek == 7) ? 0 : dayOfWeek; return dateWithinWeek.minusDays(dayOfWeek); } | DateUtils { public static LocalDate getLastSundayDate(final LocalDate dateWithinWeek) { int dayOfWeek = dateWithinWeek.getDayOfWeek().getValue(); dayOfWeek = (dayOfWeek == 7) ? 0 : dayOfWeek; return dateWithinWeek.minusDays(dayOfWeek); } } | DateUtils { public static LocalDate getLastSundayDate(final LocalDate dateWithinWeek) { int dayOfWeek = dateWithinWeek.getDayOfWeek().getValue(); dayOfWeek = (dayOfWeek == 7) ? 0 : dayOfWeek; return dateWithinWeek.minusDays(dayOfWeek); } } | DateUtils { public static LocalDate getLastSundayDate(final LocalDate dateWithinWeek) { int dayOfWeek = dateWithinWeek.getDayOfWeek().getValue(); dayOfWeek = (dayOfWeek == 7) ? 0 : dayOfWeek; return dateWithinWeek.minusDays(dayOfWeek); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } | DateUtils { public static LocalDate getLastSundayDate(final LocalDate dateWithinWeek) { int dayOfWeek = dateWithinWeek.getDayOfWeek().getValue(); dayOfWeek = (dayOfWeek == 7) ? 0 : dayOfWeek; return dateWithinWeek.minusDays(dayOfWeek); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } |
@Test public void testLoadFromStore() throws Exception { final DependenciesStore dependenciesStore = Mockito.mock(DependenciesStore.class); final DependencyGraph graph = new DependencyGraph(dependenciesStore); final Multimap<String, String> dependencyMap = MultimapBuilder.hashKeys().arrayListValues().build(); dependencyMap.put("raw1", "pds1"); dependencyMap.put("raw1", "tablefunction1"); dependencyMap.put("agg1", "raw1"); dependencyMap.put("raw2", "pds2"); dependencyMap.put("raw2", "tablefunction2"); dependencyMap.put("agg2", "raw2"); dependencyMap.put("agg3", "raw2"); dependencyMap.putAll("vds-raw", Lists.newArrayList("raw1", "raw2")); dependencyMap.put("vds-agg1", "vds-raw"); dependencyMap.putAll("vds-agg2", Lists.newArrayList("agg1", "agg2")); Mockito.when(dependenciesStore.getAll()).thenReturn(storeDependencies(dependencyMap).entrySet()); graph.loadFromStore(); for (String dependant : dependencyMap.keySet()) { for (String parent : dependencyMap.get(dependant)) { assertTrue(String.format("%s > %s", parent, dependant), isPredecessor(graph, parent, dependant)); if (dependencyByName.get(parent).getType() == DependencyType.REFLECTION) { assertTrue(String.format("%s < %s", dependant, parent), isSuccessor(graph, parent, dependant)); } } } } | public synchronized void loadFromStore() { for (Map.Entry<ReflectionId, ReflectionDependencies> entry : dependenciesStore.getAll()) { final List<ReflectionDependencyEntry> dependencies = entry.getValue().getEntryList(); if (dependencies == null || dependencies.isEmpty()) { continue; } try { setPredecessors(entry.getKey(), FluentIterable.from(dependencies) .transform(new Function<ReflectionDependencyEntry, DependencyEntry>() { @Override public DependencyEntry apply(ReflectionDependencyEntry entry) { return DependencyEntry.of(entry); } }).toSet()); } catch (DependencyException e) { logger.warn("Found a cyclic dependency while loading dependencies for {}, skipping", entry.getKey().getId(), e); } } } | DependencyGraph { public synchronized void loadFromStore() { for (Map.Entry<ReflectionId, ReflectionDependencies> entry : dependenciesStore.getAll()) { final List<ReflectionDependencyEntry> dependencies = entry.getValue().getEntryList(); if (dependencies == null || dependencies.isEmpty()) { continue; } try { setPredecessors(entry.getKey(), FluentIterable.from(dependencies) .transform(new Function<ReflectionDependencyEntry, DependencyEntry>() { @Override public DependencyEntry apply(ReflectionDependencyEntry entry) { return DependencyEntry.of(entry); } }).toSet()); } catch (DependencyException e) { logger.warn("Found a cyclic dependency while loading dependencies for {}, skipping", entry.getKey().getId(), e); } } } } | DependencyGraph { public synchronized void loadFromStore() { for (Map.Entry<ReflectionId, ReflectionDependencies> entry : dependenciesStore.getAll()) { final List<ReflectionDependencyEntry> dependencies = entry.getValue().getEntryList(); if (dependencies == null || dependencies.isEmpty()) { continue; } try { setPredecessors(entry.getKey(), FluentIterable.from(dependencies) .transform(new Function<ReflectionDependencyEntry, DependencyEntry>() { @Override public DependencyEntry apply(ReflectionDependencyEntry entry) { return DependencyEntry.of(entry); } }).toSet()); } catch (DependencyException e) { logger.warn("Found a cyclic dependency while loading dependencies for {}, skipping", entry.getKey().getId(), e); } } } DependencyGraph(DependenciesStore dependenciesStore); } | DependencyGraph { public synchronized void loadFromStore() { for (Map.Entry<ReflectionId, ReflectionDependencies> entry : dependenciesStore.getAll()) { final List<ReflectionDependencyEntry> dependencies = entry.getValue().getEntryList(); if (dependencies == null || dependencies.isEmpty()) { continue; } try { setPredecessors(entry.getKey(), FluentIterable.from(dependencies) .transform(new Function<ReflectionDependencyEntry, DependencyEntry>() { @Override public DependencyEntry apply(ReflectionDependencyEntry entry) { return DependencyEntry.of(entry); } }).toSet()); } catch (DependencyException e) { logger.warn("Found a cyclic dependency while loading dependencies for {}, skipping", entry.getKey().getId(), e); } } } DependencyGraph(DependenciesStore dependenciesStore); synchronized void loadFromStore(); synchronized void setDependencies(final ReflectionId reflectionId, Set<DependencyEntry> dependencies); synchronized void delete(ReflectionId id); } | DependencyGraph { public synchronized void loadFromStore() { for (Map.Entry<ReflectionId, ReflectionDependencies> entry : dependenciesStore.getAll()) { final List<ReflectionDependencyEntry> dependencies = entry.getValue().getEntryList(); if (dependencies == null || dependencies.isEmpty()) { continue; } try { setPredecessors(entry.getKey(), FluentIterable.from(dependencies) .transform(new Function<ReflectionDependencyEntry, DependencyEntry>() { @Override public DependencyEntry apply(ReflectionDependencyEntry entry) { return DependencyEntry.of(entry); } }).toSet()); } catch (DependencyException e) { logger.warn("Found a cyclic dependency while loading dependencies for {}, skipping", entry.getKey().getId(), e); } } } DependencyGraph(DependenciesStore dependenciesStore); synchronized void loadFromStore(); synchronized void setDependencies(final ReflectionId reflectionId, Set<DependencyEntry> dependencies); synchronized void delete(ReflectionId id); } |
@Test public void testMatchesTag() { final String testTag = "testTag"; final ReflectionGoal goal = ReflectionGoal.getDefaultInstance().newMessage() .setTag(testTag); assertTrue(ReflectionGoalChecker.checkGoal(goal, new ReflectionEntry().setGoalVersion(testTag))); } | public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testMatchesVersion() { final String testTag = "1"; final ReflectionGoal goal = ReflectionGoal.getDefaultInstance().newMessage() .setTag("wrongTag") .setVersion(Long.valueOf(testTag)); assertTrue(ReflectionGoalChecker.checkGoal(goal, new ReflectionEntry().setGoalVersion(testTag))); } | public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testMismatchNonNullVersion() { final String testTag = "1"; final ReflectionGoal goal = ReflectionGoal.getDefaultInstance().newMessage() .setTag("wrongTag") .setVersion(0L); assertFalse(ReflectionGoalChecker.checkGoal(goal, new ReflectionEntry().setGoalVersion(testTag))); } | public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testMismatchNullVersion() { final String testTag = "1"; final ReflectionGoal goal = ReflectionGoal.getDefaultInstance().newMessage() .setTag("wrongTag") .setVersion(null); assertFalse(ReflectionGoalChecker.checkGoal(goal, new ReflectionEntry().setGoalVersion(testTag))); } | public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public static boolean checkGoal(ReflectionGoal goal, Materialization materialization) { return Instance.isEqual(goal, materialization.getReflectionGoalVersion()); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testCheckHashAgainstHash(){ ReflectionGoal goal = new ReflectionGoal(); ReflectionEntry entry = new ReflectionEntry() .setReflectionGoalHash(new ReflectionGoalHash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")); assertTrue(ReflectionGoalChecker.Instance.checkHash(goal, entry)); } | public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testCheckHashAgainstNullHash(){ ReflectionGoal goal = new ReflectionGoal(); ReflectionEntry entry = new ReflectionEntry(); assertFalse(ReflectionGoalChecker.Instance.checkHash(goal, entry)); } | public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public boolean checkHash(ReflectionGoal goal, ReflectionEntry entry){ if(null == entry.getReflectionGoalHash()){ return false; } return entry.getReflectionGoalHash().equals(calculateReflectionGoalVersion(goal)); } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testHashingEmptyGoal(){ ReflectionGoal goal = new ReflectionGoal(); ReflectionGoalHash actual = ReflectionGoalChecker.Instance.calculateReflectionGoalVersion(goal); assertEquals("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", actual.getHash()); } | public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testHashingEmptyIfExcludingBlackListFieldsGoal(){ ReflectionGoal goal = new ReflectionGoal() .setTag(Long.toString(System.currentTimeMillis())) .setCreatedAt(System.currentTimeMillis()) .setModifiedAt(System.currentTimeMillis()) .setVersion(System.currentTimeMillis()) .setName("Name") .setArrowCachingEnabled(false); ReflectionGoalHash actual = ReflectionGoalChecker.Instance.calculateReflectionGoalVersion(goal); assertEquals("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", actual.getHash()); } | public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testHashingEmptyWithBoostEnabledGoal(){ ReflectionGoal goal = new ReflectionGoal() .setArrowCachingEnabled(true); ReflectionGoalHash actual = ReflectionGoalChecker.Instance.calculateReflectionGoalVersion(goal); assertEquals("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", actual.getHash()); } | public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testGetMonthStartDate() { LocalDate testDate1 = LocalDate.parse("2020-03-01"); LocalDate monthStartDate = DateUtils.getMonthStartDate(testDate1); assertEquals(testDate1, monthStartDate); LocalDate testDate2 = LocalDate.parse("2020-03-31"); LocalDate date2MonthStartDate = DateUtils.getMonthStartDate(testDate2); assertEquals(testDate1, date2MonthStartDate); } | public static LocalDate getMonthStartDate(final LocalDate dateWithinMonth) { int dayOfMonth = dateWithinMonth.getDayOfMonth(); return dateWithinMonth.minusDays((dayOfMonth - 1)); } | DateUtils { public static LocalDate getMonthStartDate(final LocalDate dateWithinMonth) { int dayOfMonth = dateWithinMonth.getDayOfMonth(); return dateWithinMonth.minusDays((dayOfMonth - 1)); } } | DateUtils { public static LocalDate getMonthStartDate(final LocalDate dateWithinMonth) { int dayOfMonth = dateWithinMonth.getDayOfMonth(); return dateWithinMonth.minusDays((dayOfMonth - 1)); } } | DateUtils { public static LocalDate getMonthStartDate(final LocalDate dateWithinMonth) { int dayOfMonth = dateWithinMonth.getDayOfMonth(); return dateWithinMonth.minusDays((dayOfMonth - 1)); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } | DateUtils { public static LocalDate getMonthStartDate(final LocalDate dateWithinMonth) { int dayOfMonth = dateWithinMonth.getDayOfMonth(); return dateWithinMonth.minusDays((dayOfMonth - 1)); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } |
@Test public void testHashingWithUniqueIdGoal(){ ReflectionGoal goal = new ReflectionGoal() .setId(new ReflectionId("xxx")); ReflectionGoalHash actual = ReflectionGoalChecker.Instance.calculateReflectionGoalVersion(goal); assertEquals("a9171a2d1e967b50401388ba1271fba59386adac44078e0a0047f9111167f1a2", actual.getHash()); } | public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testHashingWithDifferentDetails(){ ReflectionGoal goal1 = new ReflectionGoal() .setId(new ReflectionId("xxx")) .setDetails( new ReflectionDetails() .setDimensionFieldList(ImmutableList.of( new ReflectionDimensionField() .setName("field") .setGranularity(DimensionGranularity.NORMAL) )) ); ReflectionGoal goal2 = new ReflectionGoal() .setId(new ReflectionId("xxx")) .setDetails( new ReflectionDetails() .setDimensionFieldList(ImmutableList.of( new ReflectionDimensionField() .setName("field2") .setGranularity(DimensionGranularity.DATE) )) ); ReflectionGoalHash actual1 = ReflectionGoalChecker.Instance.calculateReflectionGoalVersion(goal1); ReflectionGoalHash actual2 = ReflectionGoalChecker.Instance.calculateReflectionGoalVersion(goal2); assertEquals( "We expect difrrent values for different details", "c5f4f595fb56e276b02a2e6fa6cb7fad1ca2afab691fee3a7e0465fc93fb1607", actual1.getHash() ); assertEquals( "We expect difrrent values for different details", "296a48c3f656ad3430da74353556d40fe4d0756952e2ce80cd7e6df58b064275", actual2.getHash() ); } | public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); } | ReflectionGoalChecker { public ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal){ HasherOutput hasherOutput = new HasherOutput(); Output blackListedOutput = reflectionGoalMaterializationBlackLister.apply(hasherOutput); try { reflectionGoal.writeTo(blackListedOutput, reflectionGoal); return new ReflectionGoalHash() .setHash(hasherOutput.getHasher().hash().toString()); } catch (IOException ioException) { throw new RuntimeException(ioException); } } ReflectionGoalHash calculateReflectionGoalVersion(ReflectionGoal reflectionGoal); boolean checkHash(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, ReflectionEntry entry); boolean isEqual(ReflectionGoal goal, String version); static boolean checkGoal(ReflectionGoal goal, Materialization materialization); static boolean checkGoal(ReflectionGoal goal, ReflectionEntry entry); static final ReflectionGoalChecker Instance; } |
@Test public void testMergeOptionLists() { final OptionValue optionValue0 = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "test-option0", false); final OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option1", 2); final OptionValue optionValue2 = OptionValue.createLong(OptionValue.OptionType.SESSION, "test-option2", 4); final OptionValue optionValue3 = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "test-option0", true); final OptionValue optionValue4 = OptionValue.createLong(OptionValue.OptionType.SESSION, "test-option1", 2); final OptionList localList = new OptionList(); localList.add(optionValue0); localList.add(optionValue1); localList.add(optionValue2); final OptionList changedList = new OptionList(); changedList.add(optionValue3); changedList.add(optionValue4); final OptionList expectedList = new OptionList(); expectedList.add(optionValue3); expectedList.add(optionValue4); expectedList.add(optionValue1); expectedList.add(optionValue2); changedList.mergeIfNotPresent(localList); assert changedList.equals(expectedList) : String.format("OptionLists merge incorrectly.\n\nexpected: %s \n\n" + "returned: %s", expectedList, changedList); } | public void mergeIfNotPresent(OptionList list) { final Set<OptionValue> options = Sets.newTreeSet(this); for (OptionValue optionValue : list) { if (options.add(optionValue)) { this.add(optionValue); } } } | OptionList extends ArrayList<OptionValue> { public void mergeIfNotPresent(OptionList list) { final Set<OptionValue> options = Sets.newTreeSet(this); for (OptionValue optionValue : list) { if (options.add(optionValue)) { this.add(optionValue); } } } } | OptionList extends ArrayList<OptionValue> { public void mergeIfNotPresent(OptionList list) { final Set<OptionValue> options = Sets.newTreeSet(this); for (OptionValue optionValue : list) { if (options.add(optionValue)) { this.add(optionValue); } } } } | OptionList extends ArrayList<OptionValue> { public void mergeIfNotPresent(OptionList list) { final Set<OptionValue> options = Sets.newTreeSet(this); for (OptionValue optionValue : list) { if (options.add(optionValue)) { this.add(optionValue); } } } void merge(OptionList list); void mergeIfNotPresent(OptionList list); OptionList getSystemOptions(); OptionList getNonSystemOptions(); } | OptionList extends ArrayList<OptionValue> { public void mergeIfNotPresent(OptionList list) { final Set<OptionValue> options = Sets.newTreeSet(this); for (OptionValue optionValue : list) { if (options.add(optionValue)) { this.add(optionValue); } } } void merge(OptionList list); void mergeIfNotPresent(OptionList list); OptionList getSystemOptions(); OptionList getNonSystemOptions(); } |
@Test public void testSamePrioritySuppliers() throws Exception { final CommandPool pool = newTestCommandPool(); final BlockingCommand blocking = new BlockingCommand(); pool.submit(CommandPool.Priority.HIGH, "test", blocking, false); Future<Integer> future1 = pool.submit(CommandPool.Priority.HIGH, "test", (waitInMillis) -> counter.getAndIncrement(), false); Thread.sleep(5); Future<Integer> future2 = pool.submit(CommandPool.Priority.HIGH, "test", (waitInMillis) -> counter.getAndIncrement(), false); Thread.sleep(5); Future<Integer> future3 = pool.submit(CommandPool.Priority.HIGH, "test", (waitInMillis) -> counter.getAndIncrement(), false); blocking.unblock(); Assert.assertEquals(0, (int) Futures.getUnchecked(future1)); Assert.assertEquals(1, (int) Futures.getUnchecked(future2)); Assert.assertEquals(2, (int) Futures.getUnchecked(future3)); } | @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } BoundCommandPool(final int poolSize, Tracer tracer); } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } BoundCommandPool(final int poolSize, Tracer tracer); @Override CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread); @Override void start(); @Override void close(); } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } BoundCommandPool(final int poolSize, Tracer tracer); @Override CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread); @Override void start(); @Override void close(); } |
@Test public void testDifferentPrioritySuppliers() { final CommandPool pool = newTestCommandPool(); final BlockingCommand blocking = new BlockingCommand(); pool.submit(CommandPool.Priority.HIGH, "test", blocking, false); Future<Integer> future1 = pool.submit(CommandPool.Priority.LOW, "test", (waitInMillis) -> counter.getAndIncrement(), false); Future<Integer> future2 = pool.submit(CommandPool.Priority.MEDIUM, "test", (waitInMillis) -> counter.getAndIncrement(), false); Future<Integer> future3 = pool.submit(CommandPool.Priority.HIGH, "test", (waitInMillis) -> counter.getAndIncrement(), false); blocking.unblock(); Assert.assertEquals(2, (int) Futures.getUnchecked(future1)); Assert.assertEquals(1, (int) Futures.getUnchecked(future2)); Assert.assertEquals(0, (int) Futures.getUnchecked(future3)); } | @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } BoundCommandPool(final int poolSize, Tracer tracer); } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } BoundCommandPool(final int poolSize, Tracer tracer); @Override CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread); @Override void start(); @Override void close(); } | BoundCommandPool implements CommandPool { @Override public <V> CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread) { final long time = System.currentTimeMillis(); final CommandWrapper<V> wrapper = new CommandWrapper<>(priority, descriptor, time, command); logger.debug("command {} created", descriptor); if (runInSameThread) { logger.debug("running command {} in the same calling thread", descriptor); wrapper.run(); } else { executorService.execute(wrapper); } return wrapper.getFuture(); } BoundCommandPool(final int poolSize, Tracer tracer); @Override CompletableFuture<V> submit(Priority priority, String descriptor, Command<V> command, boolean runInSameThread); @Override void start(); @Override void close(); } |
@Test public void testInvalidIdFromString() throws Exception { try { PartitionChunkId split = PartitionChunkId.of("ds1_1"); fail("ds1_1 is an invalid dataset split id"); } catch (IllegalArgumentException e) { } try { PartitionChunkId split = PartitionChunkId.of("ds2_2_"); fail("ds2_2_ is an invalid dataset split id"); } catch (IllegalArgumentException e) { } } | @JsonCreator public static PartitionChunkId of(String partitionChunkId) { final String[] ids = partitionChunkId.split(DELIMITER, 3); Preconditions.checkArgument(ids.length == 3 && !ids[0].isEmpty() && !ids[1].isEmpty() && !ids[2].isEmpty(), "Invalid dataset split id %s", partitionChunkId); long version; try { version = Long.parseLong(ids[1]); } catch (NumberFormatException e) { version = Long.MIN_VALUE; } return new PartitionChunkId(partitionChunkId, unescape(ids[0]), version, ids[2]); } | PartitionChunkId implements Comparable<PartitionChunkId> { @JsonCreator public static PartitionChunkId of(String partitionChunkId) { final String[] ids = partitionChunkId.split(DELIMITER, 3); Preconditions.checkArgument(ids.length == 3 && !ids[0].isEmpty() && !ids[1].isEmpty() && !ids[2].isEmpty(), "Invalid dataset split id %s", partitionChunkId); long version; try { version = Long.parseLong(ids[1]); } catch (NumberFormatException e) { version = Long.MIN_VALUE; } return new PartitionChunkId(partitionChunkId, unescape(ids[0]), version, ids[2]); } } | PartitionChunkId implements Comparable<PartitionChunkId> { @JsonCreator public static PartitionChunkId of(String partitionChunkId) { final String[] ids = partitionChunkId.split(DELIMITER, 3); Preconditions.checkArgument(ids.length == 3 && !ids[0].isEmpty() && !ids[1].isEmpty() && !ids[2].isEmpty(), "Invalid dataset split id %s", partitionChunkId); long version; try { version = Long.parseLong(ids[1]); } catch (NumberFormatException e) { version = Long.MIN_VALUE; } return new PartitionChunkId(partitionChunkId, unescape(ids[0]), version, ids[2]); } private PartitionChunkId(String compoundSplitId, String datasetId, long splitVersion, String splitKey); } | PartitionChunkId implements Comparable<PartitionChunkId> { @JsonCreator public static PartitionChunkId of(String partitionChunkId) { final String[] ids = partitionChunkId.split(DELIMITER, 3); Preconditions.checkArgument(ids.length == 3 && !ids[0].isEmpty() && !ids[1].isEmpty() && !ids[2].isEmpty(), "Invalid dataset split id %s", partitionChunkId); long version; try { version = Long.parseLong(ids[1]); } catch (NumberFormatException e) { version = Long.MIN_VALUE; } return new PartitionChunkId(partitionChunkId, unescape(ids[0]), version, ids[2]); } private PartitionChunkId(String compoundSplitId, String datasetId, long splitVersion, String splitKey); @JsonCreator static PartitionChunkId of(String partitionChunkId); static PartitionChunkId of(DatasetConfig config, PartitionChunk split, long splitVersion); static PartitionChunkId of(DatasetConfig config, PartitionChunkMetadata partitionChunkMetadata, long splitVersion); @JsonValue String getSplitId(); @JsonIgnore String getDatasetId(); @JsonIgnore long getSplitVersion(); @JsonIgnore String getSplitIdentifier(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(PartitionChunkId that); @Override String toString(); static SearchQuery getSplitsQuery(DatasetConfig datasetConfig); static SearchQuery getSplitsQuery(EntityId datasetId, long splitVersion); static Range<PartitionChunkId> getCurrentSplitRange(DatasetConfig datasetConfig); static Range<PartitionChunkId> getSplitRange(EntityId datasetId, long splitVersion); static Range<PartitionChunkId> getSplitRange(EntityId datasetId, long startSplitVersion, long endSplitVersion); static LegacyFindByRange<PartitionChunkId> getSplitsRange(DatasetConfig datasetConfig); static LegacyFindByRange<PartitionChunkId> getSplitsRange(EntityId datasetId, long splitVersionId); static boolean mayRequireNewDatasetId(DatasetConfig config); static LegacyFindByRange<PartitionChunkId> unsafeGetSplitsRange(DatasetConfig config); } | PartitionChunkId implements Comparable<PartitionChunkId> { @JsonCreator public static PartitionChunkId of(String partitionChunkId) { final String[] ids = partitionChunkId.split(DELIMITER, 3); Preconditions.checkArgument(ids.length == 3 && !ids[0].isEmpty() && !ids[1].isEmpty() && !ids[2].isEmpty(), "Invalid dataset split id %s", partitionChunkId); long version; try { version = Long.parseLong(ids[1]); } catch (NumberFormatException e) { version = Long.MIN_VALUE; } return new PartitionChunkId(partitionChunkId, unescape(ids[0]), version, ids[2]); } private PartitionChunkId(String compoundSplitId, String datasetId, long splitVersion, String splitKey); @JsonCreator static PartitionChunkId of(String partitionChunkId); static PartitionChunkId of(DatasetConfig config, PartitionChunk split, long splitVersion); static PartitionChunkId of(DatasetConfig config, PartitionChunkMetadata partitionChunkMetadata, long splitVersion); @JsonValue String getSplitId(); @JsonIgnore String getDatasetId(); @JsonIgnore long getSplitVersion(); @JsonIgnore String getSplitIdentifier(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(PartitionChunkId that); @Override String toString(); static SearchQuery getSplitsQuery(DatasetConfig datasetConfig); static SearchQuery getSplitsQuery(EntityId datasetId, long splitVersion); static Range<PartitionChunkId> getCurrentSplitRange(DatasetConfig datasetConfig); static Range<PartitionChunkId> getSplitRange(EntityId datasetId, long splitVersion); static Range<PartitionChunkId> getSplitRange(EntityId datasetId, long startSplitVersion, long endSplitVersion); static LegacyFindByRange<PartitionChunkId> getSplitsRange(DatasetConfig datasetConfig); static LegacyFindByRange<PartitionChunkId> getSplitsRange(EntityId datasetId, long splitVersionId); static boolean mayRequireNewDatasetId(DatasetConfig config); static LegacyFindByRange<PartitionChunkId> unsafeGetSplitsRange(DatasetConfig config); } |
@Test public void testDefaultTextFileFormatOptions() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); String tableOptions = fileFormat.toTableOptions(); assertContains("type => 'text'", tableOptions); assertContains("fieldDelimiter => ','", tableOptions); assertContains("comment => '#'", tableOptions); assertContains("\"escape\" => '\"'", tableOptions); assertContains("quote => '\"'", tableOptions); assertContains("lineDelimiter => '\r\n'", tableOptions); assertContains("extractHeader => false", tableOptions); assertContains("skipFirstLine => false", tableOptions); assertContains("autoGenerateColumnNames => true", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testLineDelimiterTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setLineDelimiter("\t"); String tableOptions = fileFormat.toTableOptions(); assertContains("lineDelimiter => '\t'", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testLineDelimiterTextFileWithSingleQuote() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setLineDelimiter("'a"); String tableOptions = fileFormat.toTableOptions(); assertContains("lineDelimiter => '''a'", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testCommentTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setComment("$"); String tableOptions = fileFormat.toTableOptions(); assertContains("comment => '$'", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testFromEpochMillis() { LocalDate extractedDate = DateUtils.fromEpochMillis(System.currentTimeMillis()); assertEquals(LocalDate.now(), extractedDate); } | public static LocalDate fromEpochMillis(final long epochMillis) { return Instant.ofEpochMilli(epochMillis).atZone(ZoneOffset.UTC).toLocalDate(); } | DateUtils { public static LocalDate fromEpochMillis(final long epochMillis) { return Instant.ofEpochMilli(epochMillis).atZone(ZoneOffset.UTC).toLocalDate(); } } | DateUtils { public static LocalDate fromEpochMillis(final long epochMillis) { return Instant.ofEpochMilli(epochMillis).atZone(ZoneOffset.UTC).toLocalDate(); } } | DateUtils { public static LocalDate fromEpochMillis(final long epochMillis) { return Instant.ofEpochMilli(epochMillis).atZone(ZoneOffset.UTC).toLocalDate(); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } | DateUtils { public static LocalDate fromEpochMillis(final long epochMillis) { return Instant.ofEpochMilli(epochMillis).atZone(ZoneOffset.UTC).toLocalDate(); } static long getStartOfLastMonth(); static LocalDate getLastSundayDate(final LocalDate dateWithinWeek); static LocalDate getMonthStartDate(final LocalDate dateWithinMonth); static LocalDate fromEpochMillis(final long epochMillis); } |
@Test public void testEscapeTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setEscape("\\"); String tableOptions = fileFormat.toTableOptions(); assertContains("\"escape\" => '\\", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testQuoteTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setQuote("\""); String tableOptions = fileFormat.toTableOptions(); assertContains("quote => '\"'", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testSingleQuoteTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setQuote("'"); String tableOptions = fileFormat.toTableOptions(); assertContains("quote => ''''", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testFieldDelimiterTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setFieldDelimiter("@"); String tableOptions = fileFormat.toTableOptions(); assertContains("fieldDelimiter => '@'", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testExtractHeaderTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setExtractHeader(true); String tableOptions = fileFormat.toTableOptions(); assertContains("extractHeader => true", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testsetSkipFirstLineTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setSkipFirstLine(true); String tableOptions = fileFormat.toTableOptions(); assertContains("skipFirstLine => true", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
@Test public void testAutoGenerateColumnNamesTextFile() throws Exception { TextFileConfig fileFormat = new TextFileConfig(); fileFormat.setAutoGenerateColumnNames(false); String tableOptions = fileFormat.toTableOptions(); assertContains("autoGenerateColumnNames => false", tableOptions); } | public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } | FileFormat { public String toTableOptions() throws IllegalArgumentException { final StringBuilder stringBuilder = new StringBuilder(); switch (getFileType()) { case TEXT: case CSV: case TSV: case PSV: final TextFileConfig textFileConfig = (TextFileConfig)this; stringBuilder.append("type => 'text', "); stringBuilder.append(format("fieldDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getFieldDelimiter()))); stringBuilder.append(format("comment => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getComment())))); stringBuilder.append(format("%1$sescape%1$s => %2$s, ", SqlUtils.QUOTE, SqlUtils.stringLiteral(singleChar(textFileConfig.getEscape())))); stringBuilder.append(format("quote => %s, ", SqlUtils.stringLiteral(singleChar(textFileConfig.getQuote())))); stringBuilder.append(format("lineDelimiter => %s, ", SqlUtils.stringLiteral(textFileConfig.getLineDelimiter()))); stringBuilder.append(format("extractHeader => %s, ", textFileConfig.getExtractHeader().toString())); stringBuilder.append(format("skipFirstLine => %s, ", textFileConfig.getSkipFirstLine().toString())); stringBuilder.append(format("autoGenerateColumnNames => %s, ", textFileConfig.getAutoGenerateColumnNames().toString())); stringBuilder.append(format("trimHeader => %s", textFileConfig.getTrimHeader().toString())); return stringBuilder.toString(); case JSON: return "type => 'json'"; case PARQUET: return "type => 'parquet'"; case ICEBERG: return "type => 'iceberg'"; case AVRO: return "type => 'avro'"; case HTTP_LOG: case UNKNOWN: throw new UnsupportedOperationException("HTTP LOG and UNKNOWN file formats are not supported"); case EXCEL: { final ExcelFileConfig excelFileConfig = (ExcelFileConfig) this; stringBuilder.append("type => 'excel', "); if (excelFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(excelFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", excelFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", excelFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => false ")); return stringBuilder.toString(); } case XLS: { final XlsFileConfig xlsFileConfig = (XlsFileConfig) this; stringBuilder.append("type => 'excel', "); if (xlsFileConfig.getSheetName() != null) { stringBuilder.append(format("sheet => %s, ", SqlUtils.stringLiteral(xlsFileConfig.getSheetName()))); } stringBuilder.append(format("extractHeader => %s, ", xlsFileConfig.getExtractHeader().toString())); stringBuilder.append(format("hasMergedCells => %s, ", xlsFileConfig.getHasMergedCells().toString())); stringBuilder.append(format("xls => true ")); return stringBuilder.toString(); } default: throw new IllegalArgumentException("Invalid file format type " + getFileType()); } } @Override String toString(); String toTableOptions(); String getName(); String getOwner(); boolean getIsFolder(); void setIsFolder(boolean isFolder); String getLocation(); List<String> getFullPath(); long getCtime(); String getVersion(); void setName(String name); void setOwner(String owner); void setFullPath(List<String> fullPath); void setCtime(long ctime); void setVersion(String version); void setLocation(String location); @JsonIgnore @SuppressWarnings({ "rawtypes", "unchecked" }) FileConfig asFileConfig(); @JsonIgnore FileType getFileType(); static FileFormat getForFile(FileConfig fileConfig); static FileFormat getForFolder(FileConfig fileConfig); static FileFormat getEmptyConfig(FileType type); static String getExtension(FileType type); static FileType getFileFormatType(List<String> extensions); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.