@PreAuthorize(Constant.ACCESS_HAS_ROLE_ADMIN) public void updateConfig(String key, String value) { logger.debug("Update Kylin Runtime Config, key=" + key + ", value=" + value); KylinConfig.getInstanceFromEnv().setProperty(key, value); }
@BeforeClass public static void setupClass() throws SQLException { staticCreateTestMetadata(); KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv(); kylinConfig.setProperty("kylin.source.jdbc.connection-url", "jdbc:vertica://fakehost:1433/database"); kylinConfig.setProperty("kylin.source.jdbc.driver", "com.vertica.jdbc.Driver"); kylinConfig.setProperty("kylin.source.jdbc.user", "user"); kylinConfig.setProperty("kylin.source.jdbc.pass", ""); kylinConfig.setProperty("kylin.source.jdbc.dialect", "vertica"); }
public static String replaceMetadataUrl(KylinConfig kylinConfig, String newUrl) { String oldUrl = kylinConfig.getMetadataUrl().toString(); kylinConfig.setProperty("kylin.metadata.url", newUrl); return oldUrl; }
public static void staticCreateTestMetadata(boolean useTestMeta, MetadataTestCaseHook hook) { try { KylinConfig.destroyInstance(); FileUtils.deleteDirectory(new File(LOCALMETA_TEMP_DATA)); if (useTestMeta) { FileUtils.copyDirectory(new File(LOCALMETA_TEST_DATA), new File(LOCALMETA_TEMP_DATA)); } if (System.getProperty(KylinConfig.KYLIN_CONF) == null && System.getenv(KylinConfig.KYLIN_CONF) == null) { System.setProperty(KylinConfig.KYLIN_CONF, LOCALMETA_TEMP_DATA); } if (hook != null) { hook.hook(); } KylinConfig config = KylinConfig.getInstanceFromEnv(); config.setMetadataUrl(LOCALMETA_TEMP_DATA); config.setProperty("kylin.env.hdfs-working-dir", "file:///tmp/kylin"); } catch (IOException e) { throw new RuntimeException(e); } }
@Test public void testCalciteExtrasProperties() { KylinConfig conf = KylinConfig.getInstanceFromEnv(); Properties extras = conf.getCalciteExtrasProperties(); assertEquals("true", extras.getProperty("caseSensitive")); assertEquals("TO_UPPER", extras.getProperty("unquotedCasing")); assertEquals("DOUBLE_QUOTE", extras.getProperty("quoting")); assertEquals("LENIENT", extras.getProperty("conformance")); conf.setProperty("kylin.query.calcite.extras-props.caseSensitive", "false"); conf.setProperty("kylin.query.calcite.extras-props.unquotedCasing", "UNCHANGED"); conf.setProperty("kylin.query.calcite.extras-props.quoting", "BRACKET"); conf.setProperty("kylin.query.calcite.extras-props.conformance", "DEFAULT"); extras = conf.getCalciteExtrasProperties(); assertEquals("false", extras.getProperty("caseSensitive")); assertEquals("UNCHANGED", extras.getProperty("unquotedCasing")); assertEquals("BRACKET", extras.getProperty("quoting")); assertEquals("DEFAULT", extras.getProperty("conformance")); } }
@Before public void setUp() throws Exception { this.createTestMetadata(); KylinConfig.getInstanceFromEnv().setProperty("kylin.query.escape-default-keyword", "true"); }
@Test public void testGetConnection() throws SQLException, IllegalAccessException { Connection connection = QueryConnection.getConnection("default"); assertNotNull(connection); Map<InternalProperty, Object> properties = dirtyReadProperties(connection); assertEquals(true, properties.get(InternalProperty.CASE_SENSITIVE)); assertEquals(Casing.TO_UPPER, properties.get(InternalProperty.UNQUOTED_CASING)); assertEquals(Quoting.DOUBLE_QUOTE, properties.get(InternalProperty.QUOTING)); ResultSet resultSet = connection.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery(); String columnName = resultSet.getMetaData().getColumnName(1); assertEquals("VALUE_ALIAS", columnName); // override connection properties KylinConfig conf = KylinConfig.getInstanceFromEnv(); conf.setProperty("kylin.query.calcite.extras-props.caseSensitive", "false"); conf.setProperty("kylin.query.calcite.extras-props.unquotedCasing", "UNCHANGED"); conf.setProperty("kylin.query.calcite.extras-props.quoting", "BRACKET"); Connection conn2 = QueryConnection.getConnection("default"); Map<InternalProperty, Object> props = dirtyReadProperties(conn2); assertEquals(false, props.get(InternalProperty.CASE_SENSITIVE)); assertEquals(Casing.UNCHANGED, props.get(InternalProperty.UNQUOTED_CASING)); assertEquals(Quoting.BRACKET, props.get(InternalProperty.QUOTING)); ResultSet resultSet1 = conn2.prepareStatement(SQL_WITH_MIXED_CASE).executeQuery(); assertEquals("value_ALIAS", resultSet1.getMetaData().getColumnName(1)); }
@Test public void testExtShareTheBase() { KylinConfig config = KylinConfig.getInstanceFromEnv(); Map<String, String> override = Maps.newHashMap(); KylinConfig configExt = KylinConfigExt.createInstance(config, override); assertTrue(config.properties == configExt.properties); config.setProperty("1234", "1234"); assertEquals("1234", configExt.getOptional("1234")); }
private void createAppendTrieDict(List<String> valueList) throws IOException { KylinConfig.getInstanceFromEnv().setProperty("kylin.dictionary.append-entry-size", "1"); AppendTrieDictionaryBuilder builder = createBuilder(); for (String value : valueList) { builder.addValue(value); } builder.build(0); }
@Test public void testKeywordDefaultDirtyHack() { { KylinConfig.getInstanceFromEnv().setProperty("kylin.query.escape-default-keyword", "true"); String sql = "select * from DEFAULT.TEST_KYLIN_FACT"; String s = QueryUtil.massageSql(sql, "default", 0, 0, "DEFAULT"); Assert.assertEquals("select * from \"DEFAULT\".TEST_KYLIN_FACT", s); } }
@Test public void testEvict() throws Exception { kylinConfig.setProperty("kylin.snapshot.ext.local.cache.max-size-gb", "0.005"); int snapshotNum = 10; int snapshotRowCnt = 100000; for (int i = 0; i < snapshotNum; i++) { buildSnapshotCache(RandomUtil.randomUUID().toString(), snapshotRowCnt); } assertTrue(RocksDBLookupTableCache.getInstance(kylinConfig).getTotalCacheSize() < 0.006 * 1024 * 1024 * 1024); }
@Test public void testVersionRetention() throws IOException, InterruptedException { KylinConfig.getInstanceFromEnv().setProperty("kylin.dictionary.append-entry-size", "4"); KylinConfig.getInstanceFromEnv().setProperty("kylin.dictionary.append-max-versions", "1"); KylinConfig.getInstanceFromEnv().setProperty("kylin.dictionary.append-version-ttl", "1000"); AppendTrieDictionaryBuilder builder = createBuilder(); builder.addValue("a"); //version 1 builder.build(0); // Check versions retention File dir = new File(LOCAL_BASE_DIR); assertEquals(1, dir.listFiles(new VersionFilter()).length); // sleep to make version 1 expired Thread.sleep(1200); //version 2 builder = createBuilder(); builder.addValue(""); builder.build(0); // Check versions retention assertEquals(1, dir.listFiles(new VersionFilter()).length); }
@Before public void beforeTest() { staticCreateTestMetadata(); KylinConfig.getInstanceFromEnv().setProperty("kylin.dictionary.append-entry-size", "50000"); BASE_DIR = KylinConfig.getInstanceFromEnv().getHdfsWorkingDirectory() + "/resources/GlobalDict" + RESOURCE_DIR + "/"; LOCAL_BASE_DIR = getLocalWorkingDirectory() + "/resources/GlobalDict" + RESOURCE_DIR + "/"; }
@Test public void testForceLimit() { KylinConfig.getInstanceFromEnv().setProperty("kylin.query.force-limit", "10"); String sql1 = "select * \nfrom DEFAULT.TEST_KYLIN_FACT"; String result = QueryUtil.massageSql(sql1, "default", 0, 0, "DEFAULT"); Assert.assertEquals("select * \nfrom DEFAULT.TEST_KYLIN_FACT\nLIMIT 10", result); String sql2 = "select 2 * 8 from DEFAULT.TEST_KYLIN_FACT"; result = QueryUtil.massageSql(sql2, "default", 0, 0, "DEFAULT"); Assert.assertEquals("select 2 * 8 from DEFAULT.TEST_KYLIN_FACT", result); }
@Test public void testCheckCacheState() throws Exception { ExtTableSnapshotInfo snapshotInfo = buildSnapshotCache(RandomUtil.randomUUID().toString(), 1000); RocksDBLookupTableCache cache = RocksDBLookupTableCache.getInstance(kylinConfig); ILookupTable cachedLookupTable = cache.getCachedLookupTable(tableDesc, snapshotInfo, false); assertNotNull(cachedLookupTable); cachedLookupTable.close(); ExtTableSnapshotInfoManager.getInstance(kylinConfig).removeSnapshot(snapshotInfo.getTableName(), snapshotInfo.getId()); cache.checkCacheState(); String cacheLocalPath = cache.getSnapshotCachePath(snapshotInfo.getTableName(), snapshotInfo.getId()); // won't cleanup because it is newly created in last 1 hour assertTrue(new File(cacheLocalPath).exists()); // change the volatile value kylinConfig.setProperty("kylin.snapshot.ext.local.cache.check.volatile", "0"); cache.checkCacheState(); // this time it should be removed. assertFalse(new File(cacheLocalPath).exists()); cachedLookupTable = cache.getCachedLookupTable(tableDesc, snapshotInfo, false); assertNull(cachedLookupTable); }
@BeforeClass public static void setUp() throws Exception { staticCreateTestMetadata(); getTestConfig().setProperty("kylin.source.jdbc.dialect", "testing"); connector = SourceConnectorFactory.getJdbcConnector(getTestConfig()); h2Conn = connector.getConnection(); h2Db = new H2Database(h2Conn, getTestConfig(), "default"); h2Db.loadAllTables(); }
@Test public void testOldDirFormat() throws IOException { KylinConfig.getInstanceFromEnv().setProperty("kylin.dictionary.append-entry-size", "4"); AppendTrieDictionaryBuilder builder = createBuilder(); builder.addValue("a"); builder.addValue("b"); builder.addValue("c"); builder.addValue("d"); builder.addValue("e"); builder.addValue("f"); builder.build(0); convertDirToOldFormat(BASE_DIR); File dir = new File(LOCAL_BASE_DIR); assertEquals(0, dir.listFiles(new VersionFilter()).length); assertEquals(3, dir.listFiles(new CachedFileFilter()).length); //convert older format to new format when builder init builder = createBuilder(); builder.build(0); assertEquals(1, dir.listFiles(new VersionFilter()).length); }
@Test public void testBackwardCompatibility() { KylinConfig config = KylinConfig.getInstanceFromEnv(); final String oldk = "kylin.test.bcc.old.key"; final String newk = "kylin.test.bcc.new.key"; assertNull(config.getOptional(oldk)); assertNotNull(config.getOptional(newk)); Map<String, String> override = Maps.newHashMap(); override.put(oldk, "1"); KylinConfigExt ext = KylinConfigExt.createInstance(config, override); assertEquals(ext.getOptional(oldk), null); assertEquals(ext.getOptional(newk), "1"); assertNotEquals(config.getOptional(newk), "1"); config.setProperty(oldk, "2"); assertEquals(config.getOptional(newk), "2"); }
@Test public void testAclDisabled() { KylinConfig testConfig = KylinConfig.getInstanceFromEnv(); testConfig.setProperty("kylin.env.zookeeper-acl-enabled", "false"); ZookeeperAclBuilder zookeeperAclBuilder = new ZookeeperAclBuilder().invoke(); Assert.assertNotNull(zookeeperAclBuilder); Assert.assertFalse(zookeeperAclBuilder.isNeedAcl()); Builder builder = zookeeperAclBuilder.setZKAclBuilder(CuratorFrameworkFactory.builder()); Assert.assertNotNull(builder); Assert.assertEquals(ZooDefs.Ids.OPEN_ACL_UNSAFE, builder.getAclProvider().getDefaultAcl()); Assert.assertNull(builder.getAuthInfos()); }
@Test public void testOldIndexFormat() throws IOException { KylinConfig.getInstanceFromEnv().setProperty("kylin.dictionary.append-entry-size", "4"); AppendTrieDictionaryBuilder builder = createBuilder(); builder.addValue("a"); builder.addValue("b"); builder.addValue("c"); builder.addValue("d"); builder.addValue("e"); builder.addValue("f"); builder.build(0); convertIndexToOldFormat(BASE_DIR); builder = createBuilder(); builder.addValue("g"); builder.addValue("h"); builder.addValue("i"); AppendTrieDictionary dict = builder.build(0); assertEquals(1, dict.getIdFromValue("a")); assertEquals(7, dict.getIdFromValue("g")); }