use of org.apache.calcite.config.CalciteConnectionConfig in project beam by apache.
the class CalciteQueryPlanner method defaultConfig.
public FrameworkConfig defaultConfig(JdbcConnection connection, Collection<RuleSet> ruleSets) {
final CalciteConnectionConfig config = connection.config();
final SqlParser.ConfigBuilder parserConfig = SqlParser.configBuilder().setQuotedCasing(config.quotedCasing()).setUnquotedCasing(config.unquotedCasing()).setQuoting(config.quoting()).setConformance(config.conformance()).setCaseSensitive(config.caseSensitive());
final SqlParserImplFactory parserFactory = config.parserFactory(SqlParserImplFactory.class, null);
if (parserFactory != null) {
parserConfig.setParserFactory(parserFactory);
}
final SchemaPlus schema = connection.getRootSchema();
final SchemaPlus defaultSchema = connection.getCurrentSchemaPlus();
final ImmutableList<RelTraitDef> traitDefs = ImmutableList.of(ConventionTraitDef.INSTANCE);
final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(schema), ImmutableList.of(defaultSchema.getName()), connection.getTypeFactory(), connection.config());
final SqlOperatorTable opTab0 = connection.config().fun(SqlOperatorTable.class, SqlStdOperatorTable.instance());
return Frameworks.newConfigBuilder().parserConfig(parserConfig.build()).defaultSchema(defaultSchema).traitDefs(traitDefs).context(Contexts.of(connection.config())).ruleSets(ruleSets.toArray(new RuleSet[0])).costFactory(BeamCostModel.FACTORY).typeSystem(connection.getTypeFactory().getTypeSystem()).operatorTable(SqlOperatorTables.chain(opTab0, catalogReader)).build();
}
use of org.apache.calcite.config.CalciteConnectionConfig in project calcite by apache.
the class PlannerImpl method createCatalogReader.
// CalciteCatalogReader is stateless; no need to store one
private CalciteCatalogReader createCatalogReader() {
final SchemaPlus rootSchema = rootSchema(defaultSchema);
final Context context = config.getContext();
final CalciteConnectionConfig connectionConfig;
if (context != null) {
connectionConfig = context.unwrap(CalciteConnectionConfig.class);
} else {
Properties properties = new Properties();
properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive()));
connectionConfig = new CalciteConnectionConfigImpl(properties);
}
return new CalciteCatalogReader(CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig);
}
use of org.apache.calcite.config.CalciteConnectionConfig in project calcite by apache.
the class PsTableFunction method eval.
public static ScannableTable eval(boolean b) {
return new ScannableTable() {
public Enumerable<Object[]> scan(DataContext root) {
final RelDataType rowType = getRowType(root.getTypeFactory());
final List<String> fieldNames = ImmutableList.copyOf(rowType.getFieldNames());
final String[] args;
final String osName = System.getProperty("os.name");
final String osVersion = System.getProperty("os.version");
Util.discard(osVersion);
switch(osName) {
case // tested on version 10.12.5
"Mac OS X":
args = new String[] { "ps", "ax", "-o", "ppid=,pid=,pgid=,tpgid=,stat=," + "user=,pcpu=,pmem=,vsz=,rss=,tty=,start=,time=,uid=,ruid=," + "sess=,comm=" };
break;
default:
args = new String[] { "ps", "--no-headers", "axo", "ppid,pid,pgrp," + "tpgid,stat,user,pcpu,pmem,vsz,rss,tty,start_time,time,euid," + "ruid,sess,comm" };
}
return Processes.processLines(args).select(new Function1<String, Object[]>() {
public Object[] apply(String line) {
final String[] fields = line.trim().split(" +");
final Object[] values = new Object[fieldNames.size()];
for (int i = 0; i < values.length; i++) {
try {
values[i] = field(fieldNames.get(i), fields[i]);
} catch (RuntimeException e) {
throw new RuntimeException("while parsing value [" + fields[i] + "] of field [" + fieldNames.get(i) + "] in line [" + line + "]");
}
}
return values;
}
private Object field(String field, String value) {
switch(field) {
case "pid":
case "ppid":
// linux only; macOS equivalent is "pgid"
case "pgrp":
// see "pgrp"
case "pgid":
case "tpgid":
return Integer.valueOf(value);
case "pcpu":
case "pmem":
return (int) (Float.valueOf(value) * 10f);
case "time":
final Matcher m1 = MINUTE_SECOND_MILLIS_PATTERN.matcher(value);
if (m1.matches()) {
final long h = Long.parseLong(m1.group(1));
final long m = Long.parseLong(m1.group(2));
final long s = Long.parseLong(m1.group(3));
return h * 3600000L + m * 60000L + s * 1000L;
}
final Matcher m2 = HOUR_MINUTE_SECOND_PATTERN.matcher(value);
if (m2.matches()) {
final long m = Long.parseLong(m2.group(1));
final long s = Long.parseLong(m2.group(2));
String g3 = m2.group(3);
while (g3.length() < 3) {
g3 = g3 + "0";
}
final long millis = Long.parseLong(g3);
return m * 60000L + s * 1000L + millis;
}
return 0L;
// linux only; macOS version is "lstart"
case "start_time":
// see "start_time"
case "lstart":
// linux only; macOS equivalent is "uid"
case "euid":
// see "euid"
case "uid":
default:
return value;
}
}
});
}
public RelDataType getRowType(RelDataTypeFactory typeFactory) {
return typeFactory.builder().add("pid", SqlTypeName.INTEGER).add("ppid", SqlTypeName.INTEGER).add("pgrp", SqlTypeName.INTEGER).add("tpgid", SqlTypeName.INTEGER).add("stat", SqlTypeName.VARCHAR).add("user", SqlTypeName.VARCHAR).add("pcpu", SqlTypeName.DECIMAL, 3, 1).add("pmem", SqlTypeName.DECIMAL, 3, 1).add("vsz", SqlTypeName.INTEGER).add("rss", SqlTypeName.INTEGER).add("tty", SqlTypeName.VARCHAR).add("start_time", SqlTypeName.VARCHAR).add("time", TimeUnit.HOUR, -1, TimeUnit.SECOND, 0).add("euid", SqlTypeName.VARCHAR).add("ruid", SqlTypeName.VARCHAR).add("sess", SqlTypeName.VARCHAR).add("command", SqlTypeName.VARCHAR).build();
}
public Statistic getStatistic() {
return Statistics.of(1000d, ImmutableList.of(ImmutableBitSet.of(1)));
}
public Schema.TableType getJdbcTableType() {
return Schema.TableType.TABLE;
}
public boolean isRolledUp(String column) {
return false;
}
public boolean rolledUpColumnValidInsideAgg(String column, SqlCall call, SqlNode parent, CalciteConnectionConfig config) {
return true;
}
};
}
use of org.apache.calcite.config.CalciteConnectionConfig in project calcite by apache.
the class RelOptLattice method getAggregate.
/**
* Retrieves a materialized table that will satisfy an aggregate query on
* the star table.
*
* <p>The current implementation creates a materialization and populates it,
* provided that {@link Lattice#auto} is true.
*
* <p>Future implementations might return materializations at a different
* level of aggregation, from which the desired result can be obtained by
* rolling up.
*
* @param planner Current planner
* @param groupSet Grouping key
* @param measureList Calls to aggregate functions
* @return Materialized table
*/
public Pair<CalciteSchema.TableEntry, TileKey> getAggregate(RelOptPlanner planner, ImmutableBitSet groupSet, List<Lattice.Measure> measureList) {
final CalciteConnectionConfig config = planner.getContext().unwrap(CalciteConnectionConfig.class);
if (config == null) {
return null;
}
final MaterializationService service = MaterializationService.instance();
boolean create = lattice.auto && config.createMaterializations();
final CalciteSchema schema = starRelOptTable.unwrap(CalciteSchema.class);
return service.defineTile(lattice, groupSet, measureList, schema, create, false);
}
use of org.apache.calcite.config.CalciteConnectionConfig in project calcite by apache.
the class DruidQueryFilterTest method testSetup.
@Before
public void testSetup() {
druidQuery = Mockito.mock(DruidQuery.class);
final CalciteConnectionConfig connectionConfigMock = Mockito.mock(CalciteConnectionConfig.class);
Mockito.when(connectionConfigMock.timeZone()).thenReturn("UTC");
Mockito.when(druidQuery.getConnectionConfig()).thenReturn(connectionConfigMock);
Mockito.when(druidQuery.getDruidTable()).thenReturn(new DruidTable(Mockito.mock(DruidSchema.class), "dataSource", null, ImmutableSet.<String>of(), "timestamp", null, null, null));
}
Aggregations