|
1 | 1 | package com.linkedin.hoptimator.planner;
|
2 | 2 |
|
| 3 | +import java.io.File; |
3 | 4 | import java.io.IOException;
|
| 5 | +import java.net.URL; |
| 6 | +import java.nio.charset.StandardCharsets; |
4 | 7 | import java.sql.SQLException;
|
5 | 8 | import java.util.ArrayList;
|
6 | 9 | import java.util.Arrays;
|
|
34 | 37 | import org.apache.calcite.tools.RuleSet;
|
35 | 38 | import org.apache.calcite.tools.RuleSets;
|
36 | 39 |
|
| 40 | +import com.google.common.io.Resources; |
| 41 | + |
37 | 42 | import com.linkedin.hoptimator.catalog.Database;
|
38 | 43 | import com.linkedin.hoptimator.catalog.DatabaseSchema;
|
39 | 44 |
|
@@ -148,7 +153,15 @@ public static HoptimatorPlanner fromModelFile(String filePath, Properties proper
|
148 | 153 | CalciteConnectionConfig connectionConfig = new CalciteConnectionConfigImpl(properties);
|
149 | 154 | CalciteConnection connection = (CalciteConnection) driver.connect("jdbc:calcite:", properties);
|
150 | 155 | SchemaPlus schema = connection.getRootSchema();
|
151 |
| - ModelHandler modelHandler = new ModelHandler(connection, filePath); // side-effect: modifies connection |
| 156 | + ModelHandler modelHandler; |
| 157 | + if (!new File(filePath).isFile()) { |
| 158 | + URL url = Resources.getResource(filePath); |
| 159 | + String text = Resources.toString(url, StandardCharsets.UTF_8); |
| 160 | + // ModelHandler can't directly read from resources, so we use "inline:" to load it dynamically |
| 161 | + modelHandler = new ModelHandler(connection, "inline:" + text); // side-effect: modifies connection |
| 162 | + } else { |
| 163 | + modelHandler = new ModelHandler(connection, filePath); // side-effect: modifies connection |
| 164 | + } |
152 | 165 | return new HoptimatorPlanner(schema);
|
153 | 166 | }
|
154 | 167 |
|
|
0 commit comments