• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AvaticaUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.calcite.avatica.AvaticaUtils的典型用法代码示例。如果您正苦于以下问题:Java AvaticaUtils类的具体用法?Java AvaticaUtils怎么用?Java AvaticaUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AvaticaUtils类属于org.apache.calcite.avatica包,在下文中一共展示了AvaticaUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parseDataSource

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
private static DataSource parseDataSource(Map<String, Object> operand) throws IOException {
	final String connection = (String) operand.get("connection");

	Map<String, Object> jdbcConfig;
	if (connection != null) {
		try (InputStream connConfig = ClassLoader.getSystemResourceAsStream(connection)) {
			jdbcConfig = new ObjectMapper().readValue(
					connConfig,
					new TypeReference<Map<String, Object>>(){}
			);
		}
	} else {
		jdbcConfig = operand;
	}

	final String dataSourceName = (String) jdbcConfig.get("dataSource");
	if (dataSourceName != null) {
		return AvaticaUtils.instantiatePlugin(DataSource.class, dataSourceName);
	}

	final String jdbcUrl = (String) jdbcConfig.get("jdbcUrl");
	final String jdbcDriver = (String) jdbcConfig.get("jdbcDriver");
	final String jdbcUser = (String) jdbcConfig.get("jdbcUser");
	final String jdbcPassword = (String) jdbcConfig.get("jdbcPassword");
	return dataSource(jdbcUrl, jdbcDriver, jdbcUser, jdbcPassword);
}
 
开发者ID:tzolov,项目名称:calcite-sql-rewriter,代码行数:27,代码来源:JournalledJdbcSchema.java


示例2: prepareAndExecuteBatch

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@Override public ExecuteBatchResult prepareAndExecuteBatch(StatementHandle h,
    List<String> sqlCommands) throws NoSuchStatementException {
  try {
    // Get the statement
    final StatementInfo info = statementCache.getIfPresent(h.id);
    if (info == null) {
      throw new NoSuchStatementException(h);
    }

    // addBatch() for each sql command
    final Statement stmt = info.statement;
    for (String sqlCommand : sqlCommands) {
      stmt.addBatch(sqlCommand);
    }

    // Execute the batch and return the results
    return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(stmt));
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:22,代码来源:JdbcMeta.java


示例3: executeBatchProtobuf

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@Override public ExecuteBatchResult executeBatchProtobuf(StatementHandle h,
    List<Requests.UpdateBatch> updateBatches) throws NoSuchStatementException {
  try {
    final StatementInfo info = statementCache.getIfPresent(h.id);
    if (null == info) {
      throw new NoSuchStatementException(h);
    }

    final PreparedStatement preparedStmt = (PreparedStatement) info.statement;
    for (Requests.UpdateBatch update : updateBatches) {
      int i = 1;
      for (Common.TypedValue value : update.getParameterValuesList()) {
        // Use the value and then increment
        preparedStmt.setObject(i++, TypedValue.protoToJdbc(value, calendar));
      }
      preparedStmt.addBatch();
    }
    return new ExecuteBatchResult(AvaticaUtils.executeLargeBatch(preparedStmt));
  } catch (SQLException e) {
    throw propagate(e);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:JdbcMeta.java


示例4: testRemoteStatementInsert

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@Test public void testRemoteStatementInsert() throws Exception {
  ConnectionSpec.getDatabaseLock().lock();
  try {
    final String t = AvaticaUtils.unique("TEST_TABLE2");
    AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url);
    Statement statement = conn.createStatement();
    final String create =
        String.format(Locale.ROOT, "create table if not exists %s ("
            + "  id int not null, msg varchar(255) not null)", t);
    int status = statement.executeUpdate(create);
    assertEquals(status, 0);

    statement = conn.createStatement();
    final String update =
        String.format(Locale.ROOT, "insert into %s values ('%d', '%s')",
            t, RANDOM.nextInt(Integer.MAX_VALUE), UUID.randomUUID());
    status = statement.executeUpdate(update);
    assertEquals(status, 1);
  } finally {
    ConnectionSpec.getDatabaseLock().unlock();
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:RemoteMetaTest.java


示例5: getObject

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@Override public Object getObject() throws SQLException {
  final Object object = super.getObject();
  if (object == null || object instanceof ArrayImpl) {
    return object;
  } else if (object instanceof List) {
    List<?> list = (List<?>) object;
    // Run the array values through the component accessor
    List<Object> convertedValues = new ArrayList<>(list.size());
    for (Object val : list) {
      if (null == val) {
        convertedValues.add(null);
      } else {
        // Set the current value in the SlotGetter so we can use the Accessor to coerce it.
        componentSlotGetter.slot = val;
        convertedValues.add(convertValue());
      }
    }
    return convertedValues;
  }
  // The object can be java array in case of user-provided class for row storage.
  return AvaticaUtils.primitiveList(object);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:23,代码来源:AbstractCursor.java


示例6: apply

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
public ExecuteResponse apply(ExecuteRequest request) {
  try (final Context ignore = executeTimer.start()) {
    try {
      final Meta.ExecuteResult executeResult = meta.execute(request.statementHandle,
          request.parameterValues, AvaticaUtils.toSaturatedInt(request.maxRowCount));

      final List<ResultSetResponse> results = new ArrayList<>(executeResult.resultSets.size());
      for (Meta.MetaResultSet metaResultSet : executeResult.resultSets) {
        results.add(toResponse(metaResultSet));
      }
      return new ExecuteResponse(results, false, serverLevelRpcMetadata);
    } catch (NoSuchStatementException e) {
      return new ExecuteResponse(null, true, serverLevelRpcMetadata);
    }
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:17,代码来源:LocalService.java


示例7: testUnique

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
/** Unit test for
 * {@link org.apache.calcite.avatica.AvaticaUtils#unique(java.lang.String)}. */
@Test public void testUnique() {
  // Below, the "probably" comments indicate the strings that will be
  // generated the first time you run the test.
  final Set<String> list = new LinkedHashSet<>();
  list.add(AvaticaUtils.unique("a")); // probably "a"
  assertThat(list.size(), is(1));
  list.add(AvaticaUtils.unique("a")); // probably "a_1"
  assertThat(list.size(), is(2));
  list.add(AvaticaUtils.unique("b")); // probably "b"
  assertThat(list.size(), is(3));
  list.add(AvaticaUtils.unique("a_1")); // probably "a_1_3"
  assertThat(list.size(), is(4));
  list.add(AvaticaUtils.unique("A")); // probably "A"
  assertThat(list.size(), is(5));
  list.add(AvaticaUtils.unique("a")); // probably "a_5"
  assertThat(list.size(), is(6));
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:20,代码来源:AvaticaUtilsTest.java


示例8: createResultSet

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
private <E> MetaResultSet createResultSet(Enumerable<E> enumerable,
                                          Class clazz, String... names) {
    final List<ColumnMetaData> columns = new ArrayList<>();
    final List<Field> fields = new ArrayList<>();
    final List<String> fieldNames = new ArrayList<>();
    for (String name : names) {
        final int index = fields.size();
        final String fieldName = AvaticaUtils.toCamelCase(name);
        final Field field;
        try {
            field = clazz.getField(fieldName);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        columns.add(columnMetaData(name, index, field.getType()));
        fields.add(field);
        fieldNames.add(fieldName);
    }
    //noinspection unchecked
    final Iterable<Object> iterable = (Iterable<Object>) (Iterable) enumerable;
    return createResultSet(Collections.<String, Object>emptyMap(),
            columns, CursorFactory.record(clazz, fields, fieldNames),
            new Frame(0, true, iterable));
}
 
开发者ID:bitnine-oss,项目名称:octopus,代码行数:25,代码来源:CalciteMetaImpl.java


示例9: createResultSet

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
private <E> MetaResultSet createResultSet(Enumerable<E> enumerable,
    Class clazz, String... names) {
  final List<ColumnMetaData> columns = new ArrayList<>();
  final List<Field> fields = new ArrayList<>();
  final List<String> fieldNames = new ArrayList<>();
  for (String name : names) {
    final int index = fields.size();
    final String fieldName = AvaticaUtils.toCamelCase(name);
    final Field field;
    try {
      field = clazz.getField(fieldName);
    } catch (NoSuchFieldException e) {
      throw new RuntimeException(e);
    }
    columns.add(columnMetaData(name, index, field.getType(), false));
    fields.add(field);
    fieldNames.add(fieldName);
  }
  //noinspection unchecked
  final Iterable<Object> iterable = (Iterable<Object>) (Iterable) enumerable;
  return createResultSet(Collections.<String, Object>emptyMap(),
      columns, CursorFactory.record(clazz, fields, fieldNames),
      new Frame(0, true, iterable));
}
 
开发者ID:qubole,项目名称:quark,代码行数:25,代码来源:QuarkMetaImpl.java


示例10: createResultSet

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
private MetaResultSet createResultSet(List iterable, Class clazz, String... names) {
    final List<ColumnMetaData> columns = new ArrayList<ColumnMetaData>();
    final List<Field> fields = new ArrayList<Field>();
    final List<String> fieldNames = new ArrayList<String>();
    for (String name : names) {
        final int index = fields.size();
        final String fieldName = AvaticaUtils.toCamelCase(name);
        final Field field;
        try {
            field = clazz.getField(fieldName);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
        columns.add(columnMetaData(name, index, field.getType(), true));
        fields.add(field);
        fieldNames.add(fieldName);
    }

    CursorFactory cursorFactory = CursorFactory.record(clazz, fields, fieldNames);
    Signature signature = new Signature(columns, "", null, Collections.<String, Object> emptyMap(), cursorFactory, StatementType.SELECT);
    StatementHandle sh = this.createStatement(connection().handle);
    Frame frame = new Frame(0, true, iterable);

    return MetaResultSet.create(connection().id, sh.id, true, signature, frame);
}
 
开发者ID:apache,项目名称:kylin,代码行数:27,代码来源:KylinMeta.java


示例11: toOp

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
private SqlOperator toOp(String op, Map<String, Object> map) {
  // TODO: build a map, for more efficient lookup
  // TODO: look up based on SqlKind
  final List<SqlOperator> operatorList =
      SqlStdOperatorTable.instance().getOperatorList();
  for (SqlOperator operator : operatorList) {
    if (operator.getName().equals(op)) {
      return operator;
    }
  }
  String class_ = (String) map.get("class");
  if (class_ != null) {
    return AvaticaUtils.instantiatePlugin(SqlOperator.class, class_);
  }
  return null;
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:RelJson.java


示例12: visit

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
public void visit(JsonCustomSchema jsonSchema) {
  try {
    final SchemaPlus parentSchema = currentMutableSchema("sub-schema");
    checkRequiredAttributes(jsonSchema, "name", "factory");
    final SchemaFactory schemaFactory =
        AvaticaUtils.instantiatePlugin(SchemaFactory.class,
            jsonSchema.factory);
    final Schema schema =
        schemaFactory.create(
            parentSchema, jsonSchema.name, operandMap(jsonSchema, jsonSchema.operand));
    final SchemaPlus schemaPlus = parentSchema.add(jsonSchema.name, schema);
    populateSchema(jsonSchema, schemaPlus);
  } catch (Exception e) {
    throw new RuntimeException("Error instantiating " + jsonSchema, e);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:17,代码来源:ModelHandler.java


示例13: extractUsingArray

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
/**
 * Converts an Array into a List using {@link Array#getArray()}. This implementation assumes
 * a non-nested array. Use {link {@link #extractUsingResultSet(Array, Calendar)} if nested
 * arrays may be possible.
 */
static List<?> extractUsingArray(Array array, Calendar calendar) throws SQLException {
  // No option but to guess as to what the type actually is...
  Object o = array.getArray();
  if (o instanceof List) {
    return (List<?>) o;
  }
  // Assume that it's a Java array.
  return AvaticaUtils.primitiveList(o);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:15,代码来源:JdbcResultSet.java


示例14: setMaxRows

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
/**
 * Sets the provided maximum number of rows on the given statement.
 *
 * @param statement The JDBC Statement to operate on
 * @param maxRowCount The maximum number of rows which should be returned for the query
 */
void setMaxRows(Statement statement, long maxRowCount) throws SQLException {
  // Special handling of maxRowCount as JDBC 0 is unlimited, our meta 0 row
  if (maxRowCount > 0) {
    AvaticaUtils.setLargeMaxRows(statement, maxRowCount);
  } else if (maxRowCount < 0) {
    statement.setMaxRows(0);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:15,代码来源:JdbcMeta.java


示例15: testMalformedRequest

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@Test public void testMalformedRequest() throws Exception {
  URL url = new URL("http://localhost:" + this.port);

  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestMethod("POST");
  conn.setDoInput(true);
  conn.setDoOutput(true);

  try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
    // Write some garbage data
    wr.write(new byte[] {0, 1, 2, 3, 4, 5, 6, 7});
    wr.flush();
    wr.close();
  }
  final int responseCode = conn.getResponseCode();
  assertEquals(500, responseCode);
  final InputStream inputStream = conn.getErrorStream();
  byte[] responseBytes = AvaticaUtils.readFullyToBytes(inputStream);
  ErrorResponse response;
  switch (this.serialization) {
  case JSON:
    response = JsonService.MAPPER.readValue(responseBytes, ErrorResponse.class);
    assertTrue("Unexpected error message: " + response.errorMessage,
        response.errorMessage.contains("Illegal character"));
    break;
  case PROTOBUF:
    ProtobufTranslation pbTranslation = new ProtobufTranslationImpl();
    Response genericResp = pbTranslation.parseResponse(responseBytes);
    assertTrue("Response was not an ErrorResponse, but was " + genericResp.getClass(),
        genericResp instanceof ErrorResponse);
    response = (ErrorResponse) genericResp;
    assertTrue("Unexpected error message: " + response.errorMessage,
        response.errorMessage.contains("contained an invalid tag"));
    break;
  default:
    fail("Unhandled serialization " + this.serialization);
    throw new RuntimeException();
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:40,代码来源:RemoteMetaTest.java


示例16: validate

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override public void validate(Array expected, Array actual) throws SQLException {
  // Need to compare the byte arrays.
  List<Byte> expectedArray =
      (List<Byte>) AvaticaUtils.primitiveList(expected.getArray());
  List<Byte> actualArray =
      (List<Byte>) AvaticaUtils.primitiveList(actual.getArray());
  assertEquals(expectedArray.size(), actualArray.size());

  for (int j = 0; j < expectedArray.size(); j++) {
    Byte expectedByte = expectedArray.get(j);
    Byte actualByte = actualArray.get(j);
    assertEquals(expectedByte, actualByte);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:16,代码来源:ArrayTypeTest.java


示例17: append

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
private void append(StringBuilder buf, Object o) {
  if (o == null) {
    buf.append("null");
  } else if (o.getClass().isArray()) {
    append(buf, AvaticaUtils.primitiveList(o));
  } else {
    buf.append(o);
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:10,代码来源:ArrayImpl.java


示例18: send

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
public byte[] send(byte[] request) {
  // TODO back-off policy?
  while (true) {
    try {
      final HttpURLConnection connection = openConnection();
      connection.setRequestMethod("POST");
      connection.setDoInput(true);
      connection.setDoOutput(true);
      try (DataOutputStream wr = new DataOutputStream(connection.getOutputStream())) {
        wr.write(request);
        wr.flush();
        wr.close();
      }
      final int responseCode = connection.getResponseCode();
      final InputStream inputStream;
      if (responseCode == HttpURLConnection.HTTP_UNAVAILABLE) {
        // Could be sitting behind a load-balancer, try again.
        continue;
      } else if (responseCode != HttpURLConnection.HTTP_OK) {
        inputStream = connection.getErrorStream();
        if (inputStream == null) {
          // HTTP Transport exception that resulted in no content coming back
          throw new RuntimeException("Failed to read data from the server: HTTP/" + responseCode);
        }
      } else {
        inputStream = connection.getInputStream();
      }
      return AvaticaUtils.readFullyToBytes(inputStream);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:34,代码来源:AvaticaHttpClientImpl.java


示例19: prepareAndExecute

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override public ExecuteResult prepareAndExecute(StatementHandle h, String sql, long maxRowCount,
    PrepareCallback callback) throws NoSuchStatementException {
  // The old semantics were that maxRowCount was also treated as the maximum number of
  // elements in the first Frame of results. A value of -1 would also preserve this, but an
  // explicit (positive) number is easier to follow, IMO.
  return prepareAndExecute(h, sql, maxRowCount, AvaticaUtils.toSaturatedInt(maxRowCount),
      callback);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:10,代码来源:RemoteMeta.java


示例20: testLongToIntegerTranslation

import org.apache.calcite.avatica.AvaticaUtils; //导入依赖的package包/类
@Test public void testLongToIntegerTranslation() {
  long[] longValues = new long[] {Integer.MIN_VALUE, -5, 0, 1, Integer.MAX_VALUE,
    ((long) Integer.MAX_VALUE) + 1L, Long.MAX_VALUE};
  int[] convertedValues = AvaticaUtils.toSaturatedInts(longValues);
  int[] intValues = new int[] {Integer.MIN_VALUE, -5, 0, 1, Integer.MAX_VALUE,
    Integer.MAX_VALUE, Integer.MAX_VALUE};
  assertArrayEquals(convertedValues, intValues);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:9,代码来源:AvaticaUtilsTest.java



注:本文中的org.apache.calcite.avatica.AvaticaUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MessageEnvelope类代码示例发布时间:2022-05-22
下一篇:
Java DHBasicKeyPairGenerator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap