title: [Amazon](500310) Invalid operation: Assert
body: <p>I am using spark-redshift and querying redshift data using pyspark for processing.</p>
  
  <p>The query works fine if i run on redshift using workbench etc.But spark-redshift unloads data to s3 and then retrieves it and it is throwing the following error when i run it.</p>
  
  <pre><code>py4j.protocol.Py4JJavaError: An error occurred while calling o124.save.
  : java.sql.SQLException: [Amazon](500310) Invalid operation: Assert
  Details: 
   -----------------------------------------------
    error:  Assert
    code:      1000
    context:   !AmLeaderProcess - 
    query:     583860
    location:  scheduler.cpp:642
    process:   padbmaster [pid=31521]
    -----------------------------------------------;
      at com.amazon.redshift.client.messages.inbound.ErrorResponse.toErrorException(ErrorResponse.java:1830)
      at com.amazon.redshift.client.PGMessagingContext.handleErrorResponse(PGMessagingContext.java:822)
      at com.amazon.redshift.client.PGMessagingContext.handleMessage(PGMessagingContext.java:647)
      at com.amazon.jdbc.communications.InboundMessagesPipeline.getNextMessageOfClass(InboundMessagesPipeline.java:312)
      at com.amazon.redshift.client.PGMessagingContext.doMoveToNextClass(PGMessagingContext.java:1080)
      at com.amazon.redshift.client.PGMessagingContext.getErrorResponse(PGMessagingContext.java:1048)
      at com.amazon.redshift.client.PGClient.handleErrorsScenario2ForPrepareExecution(PGClient.java:2524)
      at com.amazon.redshift.client.PGClient.handleErrorsPrepareExecute(PGClient.java:2465)
      at com.amazon.redshift.client.PGClient.executePreparedStatement(PGClient.java:1420)
      at com.amazon.redshift.dataengine.PGQueryExecutor.executePreparedStatement(PGQueryExecutor.java:370)
      at com.amazon.redshift.dataengine.PGQueryExecutor.execute(PGQueryExecutor.java:245)
      at com.amazon.jdbc.common.SPreparedStatement.executeWithParams(Unknown Source)
      at com.amazon.jdbc.common.SPreparedStatement.execute(Unknown Source)
      at com.databricks.spark.redshift.JDBCWrapper$$anonfun$executeInterruptibly$1.apply(RedshiftJDBCWrapper.scala:108)
      at com.databricks.spark.redshift.JDBCWrapper$$anonfun$executeInterruptibly$1.apply(RedshiftJDBCWrapper.scala:108)
      at com.databricks.spark.redshift.JDBCWrapper$$anonfun$2.apply(RedshiftJDBCWrapper.scala:126)
      at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
      at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  Caused by: com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation: Assert
  </code></pre>
  
  <p>The query which gets generated:</p>
  
  <pre><code>UNLOAD ('SELECT “x”,”y" FROM (select x,y from table_name where 
  ((load_date=20171226 and hour&gt;=16) or (load_date between 20171227 and 
  20171226) or (load_date=20171227 and hour&lt;=16))) ') TO ‘s3:s3path' WITH 
  CREDENTIALS ‘aws_access_key_id=xxx;aws_secret_access_key=yyy' ESCAPE 
  MANIFEST
  </code></pre>
  
  <p>What is the issue here and how can i resolve this.</p>