Tabnine Logo
SqlUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
SqlUtils
in
com.dremio.common.utils

Best Java code snippets using com.dremio.common.utils.SqlUtils (Showing top 20 results out of 315)

origin: dremio/dremio-oss

  @Override
  public String apply(String input) {
   return quoteIdentifier(input);
  }};
}
origin: dremio/dremio-oss

@Override
public String visit(ExpColumnReference col) throws Exception {
 String tableAlias = col.getTable();
 if (tableAlias == null && isKeyword(col.getName())) {
  tableAlias = tableName;
 }
 if (tableAlias == null) {
  return quoteIdentifier(col.getName());
 } else {
  return format("%s.%s", quoteIdentifier(tableAlias), quoteIdentifier(col.getName()));
 }
}
origin: dremio/dremio-oss

 @Override
 public void setValue(UserSession session, String value) {
  session.defaultSchemaPath = Strings.isNullOrEmpty(value) ? null : new NamespaceKey(SqlUtils.parseSchemaPath(value));
 }
},
origin: dremio/dremio-oss

/**
 * quote the identifier if it is a:
 *  - doesn't start with a character,
 *  - contains non-alphanumeric characters or
 *  - is a reserved keyword
 * @param id
 * @return
 */
public static String quoteIdentifier(final String id) {
 if (id.isEmpty()) {
  return id;
 }
 if (isKeyword(id)) {
  return quoteString(id);
 }
 if (Character.isAlphabetic(id.charAt(0)) && ALPHANUM_MATCHER.matchesAllOf(id)) {
  return id;
 }
 // Special case
 if (NEWLINE_MATCHER.matchesAnyOf(id)) {
  return quoteUnicodeString(id);
 }
 return quoteString(id);
}
origin: dremio/dremio-oss

 private String quoteLiteral(String value, DataType type) {
  if (type == DataType.TEXT) {
   return stringLiteral(value);
  } else if (type == DataType.DATE) {
   return "DATE " + stringLiteral(value);
  } else if (type == DataType.TIME) {
   return "TIME " + stringLiteral(value);
  } else if (type == DataType.DATETIME) {
   return "TIMESTAMP " + stringLiteral(value);
  }

  return value;
 }
}
origin: dremio/dremio-oss

@Override
public String apply(String input) {
 RelDataTypeField field = type.getField(input, false, false);
 if(field == null){
  throw UserException.validationError()
   .message("Unable to find field %s in table %s. Available fields were: %s.",
     input,
     SqlUtils.quotedCompound(path),
     FluentIterable.from(type.getFieldNames()).transform(SqlUtils.QUOTER).join(Joiner.on(", "))
    ).build(logger);
 }
 return field.getName();
}
origin: dremio/dremio-oss

@Test
public void testIsKeyword() {
 assertTrue(SqlUtils.isKeyword("USER"));
 assertTrue(SqlUtils.isKeyword("FiLeS"));
 assertFalse(SqlUtils.isKeyword("myUSER"));
}
origin: dremio/dremio-oss

private String quoted(String value, DataType type) {
 if (type == null || type == TEXT) {
  return stringLiteral(value);
 } else if (type == DATE) {
  if (value == null) {
   return "CAST (null as DATE)";
  }
  return "DATE " + stringLiteral(value);
 } else if (type == TIME) {
  if (value == null) {
   return "CAST (null as TIME)";
  }
  return "TIME " + stringLiteral(value);
 } else if (type == DATETIME) {
  if (value == null) {
   return "CAST (null as TIMESTAMP)";
  }
  return "TIMESTAMP " + stringLiteral(value);
 } else {
  return value;
 }
}
origin: dremio/dremio-oss

 @Override
 public ReflectionGoal apply(Ord<ReflectionDetails> reflectionDetails) {
  return new ReflectionGoal()
   .setName(String.format("AUTO_%s_RAW_%d", SqlUtils.quotedCompound(datasetConfig.getFullPathList()), reflectionDetails.i))
   .setDetails(reflectionDetails.e)
   .setType(ReflectionType.RAW);
 }
});
origin: dremio/dremio-oss

/**
 * puts back ticks around components if they look like reserved keywords and joins them with .
 * @param pathComponents can not contain nulls
 * @return a dot delimited path
 * Convert a list of path components to fully qualified dotted schema path
 * [a,b,c]      -> a.b.c
 * [a,b,c-1]    -> a.b.`c-1`
 * [a,b,c.json] -> a.b.`c.json`
 */
public static String constructFullPath(Collection<String> pathComponents) {
 final List<String> quotedPathComponents = Lists.newArrayList();
 for (final String component : pathComponents) {
  checkNotNull(component);
  quotedPathComponents.add(SqlUtils.quoteIdentifier(component));
 }
 return KEY_JOINER.join(quotedPathComponents);
}
origin: dremio/dremio-oss

private String prepareValue(final String value, DataType type) throws Exception {
 if (value == null) {
  return "NULL";
 }
 switch (type) {
  case BOOLEAN:
  case DECIMAL:
  case FLOAT:
  case INTEGER:
   return value;
  case DATE:
  case DATETIME:
  case TEXT:
  case TIME:
   return stringLiteral(value);
  default:
   throw new UnsupportedOperationException("prepareValue can not be aplied to " + type.name());
 }
}
origin: dremio/dremio-oss

 @Test
 public void testParseSchemaPath() {
  assertEquals(asList("a", "b", "c"), SqlUtils.parseSchemaPath("a.b.c"));
  assertEquals(asList("a"), SqlUtils.parseSchemaPath("a"));
  assertEquals(asList("a", "b.c", "d"), SqlUtils.parseSchemaPath("a.\"b.c\".d"));
  assertEquals(asList("a", "c"), SqlUtils.parseSchemaPath("a..c"));
 }
}
origin: dremio/dremio-oss

 @Override
 public ReflectionGoal apply(Ord<ReflectionDetails> reflectionDetails) {
  return new ReflectionGoal()
   .setName(String.format("AUTO_%s_AGG_%d", SqlUtils.quotedCompound(datasetConfig.getFullPathList()), reflectionDetails.i))
   .setDetails(reflectionDetails.e)
   .setType(ReflectionType.AGGREGATION);
 }
});
origin: dremio/dremio-oss

private String formatSQLWithSubQuery(String sql, String alias) {
 if (isStar && orders.isEmpty() && evaledFilters.isEmpty() && groupBys.isEmpty() && joins.isEmpty()) {
  return sql;
 } else {
  if (alias == null) {
   throw new UnsupportedOperationException("the subquery should be assigned an alias: " + sql);
  }
  return formatSQL(evaledCols, orders, "(\n" + indent(sql) + "\n) " + quoteIdentifier(alias), joins, evaledFilters, groupBys);
 }
}
origin: dremio/dremio-oss

@Override
public String getFunctionExpr(String expr, Object... args) {
 checkArgument(args.length == 2 && args[0] != null && args[1] != null, "Expected the split position type and index as arguments");
 SplitPositionType splitPositionType = (SplitPositionType) args[0];
 Integer index = (Integer) args[1];
 return String.format("%s(%s, %s, %s, %d)",
   SplitPattern.REGEXP_SPLIT,
   expr,
   getDelimiterRegexLiteral(false),
   stringLiteral(splitPositionType.toString()),
   index
 );
}
origin: dremio/dremio-oss

private void assertFoldersExist(List<String> expFolders) throws Exception {
 for (String folderPath : expFolders) {
  NamespaceKey folderKey = new NamespaceKey(SqlUtils.parseSchemaPath(folderPath));
  namespaceService.getFolder(folderKey); // if the folder doesn't exit we get an exception
 }
}
origin: dremio/dremio-oss

private static List<NameAndGranularity> qualifyColumnsWithGranularity(DremioTable table, List<NameAndGranularity> strings){
 final RelDataType type = table.getRowType(JavaTypeFactoryImpl.INSTANCE);
 return strings.stream().map(input -> {
   RelDataTypeField field = type.getField(input.getName(), false, false);
   if(field == null){
    throw UserException.validationError()
     .message("Unable to find field %s in table %s. Available fields were: %s.",
       input.getName(),
       SqlUtils.quotedCompound(table.getPath().getPathComponents()),
       FluentIterable.from(type.getFieldNames()).transform(SqlUtils.QUOTER).join(Joiner.on(", "))
      ).build(logger);
   }
   return new NameAndGranularity(field.getName(), input.getGranularity());
  }).collect(Collectors.toList());
}
origin: dremio/dremio-oss

<T> String generateCardGenQuery(String inputColName, String datasetPreviewTable, List<TransformRuleWrapper<T>> evaluators) {
 StringBuilder queryBuilder = new StringBuilder();
 String inputExpr = String.format("%s.%s", quoteIdentifier("dremio_preview_data"), quoteIdentifier(inputColName));
 List<String> exprs = Lists.newArrayList();
 for(int i=0; i<evaluators.size(); i++) {
  if (evaluators.get(i).canGenerateExamples()) {
   final String expr = evaluators.get(i).getExampleFunctionExpr(inputExpr);
   final String outputColAlias = "example_" + i;
   exprs.add(String.format("%s AS %s", expr, outputColAlias));
  }
 }
 exprs.add(String.format("%s AS inputCol", inputExpr));
 queryBuilder.append("SELECT\n");
 queryBuilder.append(Joiner.on(",\n").join(exprs));
 queryBuilder.append(format("\nFROM %s as dremio_preview_data", datasetPreviewTable));
 queryBuilder.append(format("\nWHERE %s IS NOT NULL", quoteIdentifier(inputColName)));
 queryBuilder.append(format("\nLIMIT %d", Card.EXAMPLES_TO_SHOW));
 return queryBuilder.toString();
}
origin: dremio/dremio-oss

@Override
public String visit(FieldConvertDateToText dateToText) throws Exception {
 return format(
   "TO_CHAR(%s, %s)",
   eval(fieldTransformation.getOperand()),
   stringLiteral(dateToText.getFormat()));
}
origin: dremio/dremio-oss

private void assertFoldersDoNotExist(List<String> expFolders) throws Exception {
 for (String folderPath : expFolders) {
  NamespaceKey folderKey = new NamespaceKey(SqlUtils.parseSchemaPath(folderPath));
  try {
   namespaceService.getFolder(folderKey); // if the folder doesn't exit we get an exception
   fail();
  } catch (NamespaceNotFoundException ex) { /* no-op */ }
 }
}
com.dremio.common.utilsSqlUtils

Javadoc

Utility methods to quote or find reserved keywords.

Most used methods

  • quoteIdentifier
    quote the identifier if it is a: - doesn't start with a character, - contains non-alphanumeric chara
  • isKeyword
    Is the given id a reserved keyword?
  • parseSchemaPath
    Parse the schema path into a list of schema entries.
  • quotedCompound
  • stringLiteral
    Convert given string value as string literal in SQL.
  • quoteString
  • quoteUnicodeString

Popular in Java

  • Running tasks concurrently on multiple threads
  • scheduleAtFixedRate (Timer)
  • getApplicationContext (Context)
  • getContentResolver (Context)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now